c# - C# - System.Data.SqlClient.SqlException:'Incorrect syntax near')'.'是sql查询错误还是什么?

我正在使用Visual Studio 2019和SQL Server Management Studio。

CustomerDetails.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerDetails.aspx.cs" Inherits="CustomerInfo.CustomerDetails" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">


<head runat="server">


 <title></title>


 <style type="text/css">


 .auto-style1 {


 text-align: center;


 }


 .auto-style2 {


 width: 29%;


 height: 119px;


 margin-left: 51px;


 }


 .auto-style3 {


 width: 240px;


 }


 .auto-style4 {


 width: 240px;


 text-align: right;


 }


 </style>


</head>


<body>


 <form id="form1" runat="server">


 <div>


 <h3 class="auto-style1">Enter Details</h3>


 </div>


 <p>


 &nbsp;</p>


 <table align="center" class="auto-style2">


 <tr>


 <td class="auto-style4">User Name :</td>


 <td>


 <asp:TextBox ID="name" runat="server" Width="200px"></asp:TextBox>


 </td>


 </tr>


 <tr>


 <td class="auto-style4">Email :</td>


 <td>


 <asp:TextBox ID="mail" runat="server" Width="200px"></asp:TextBox>


 </td>


 </tr>


 <tr>


 <td class="auto-style4">Password :</td>


 <td>


 <asp:TextBox ID="password" runat="server" Width="200px"></asp:TextBox>


 </td>


 </tr>


 <tr>


 <td class="auto-style3">&nbsp;</td>


 <td>


 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" Width="100px" />


 </td>


 </tr>


 </table>


 <asp:Label ID="Label1" runat="server" ForeColor="Green" Visible="False"></asp:Label>


 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Customer_Info_TableConnectionString %>" SelectCommand="SELECT * FROM [cus_table]"></asp:SqlDataSource>


 </form>


</body>


</html>



我创建了网页设计,按下按钮我得到这个错误:

Exception thrown :'System.Data.SqlClient.SqlException'in System.Data.dll
an exception of type'System.Data.SqlClient.SqlException'occurred in System.Data.dll but was not handled in user code
Incorrect syntax near')'.

CustomerDetails.aspx.cs


using System;


using System.Collections.Generic;


using System.Linq;


using System.Web;


using System.Web.UI;


using System.Web.UI.WebControls;


using System.Data.SqlClient;


using System.Configuration;



namespace CustomerInfo


{


 public partial class CustomerDetails : System.Web.UI.Page


 {


 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Customer_Info_TableConnectionString"].ConnectionString);



 protected void Page_Load(object sender, EventArgs e)


 {


 }



 protected void Button1_Click(object sender, EventArgs e)


 {


 SqlCommand cmd = new SqlCommand("insert into [dbo].[cus_table]('" + name.Text+"','"+name.Text+"','"+mail.Text+"','"+password.Text+"')",con);



 con.Open();


 cmd.ExecuteNonQuery();


 con.Close();



 Label1.Visible = true;


 Label1.Text ="Information uploaded Successfully! :)";



 name.Text ="";


 mail.Text ="";


 password.Text ="";


 }


 }


} 



web.config


<connectionStrings>


 <add name="Customer_Info_TableConnectionString" 


 connectionString="Data Source=DESKTOP-B44TBSQ;Initial Catalog=Customer_Info_Table;Integrated Security=True"


 providerName="System.Data.SqlClient" />


</connectionStrings>



SQL Server:


CREATE TABLE [dbo].[cus_table]


(


 [id] [int] IDENTITY(1,1) NOT NULL,


 [name] [nvarchar](50) NOT NULL,


 [mail] [nvarchar](50) NOT NULL,


 [password] [nvarchar](50) NOT NULL


) ON [PRIMARY]


GO



时间: 原作者:

  • 未定义未定义
  • 未定义
  • 永远不要将密码存储为文本;使用salt对它们进行哈希验证(冗长而乏味,但是重要的主题),或者在编写密码管理器时使用强加密,

请注意,Dapper还将打开和关闭连接,参数封装和(使用Query<T>等时)解析结果处理为实例,


var pwHash = ... not shown; note: you'd usually need to invent and store the"salt", too


conn.Execute(@"


 insert into [dbo].[cus_table] (name, mail, passwordHash)


 values (@name, @mail, @pwHash)",


 new {


 name = name.Text,


 mail = mail.Text,


 pwHash = pwHash


 });



Label1.Visible = true;


Label1.Text ="Information uploaded Successfully! :)";



原作者:
...