Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';System.Data.SqlClient.SqlException';在System.Data.dll中(';附近的“语法不正确”)'&)?_C#_Sql_Sql Server_Exception_Ado.net - Fatal编程技术网

C# ';System.Data.SqlClient.SqlException';在System.Data.dll中(';附近的“语法不正确”)'&)?

C# ';System.Data.SqlClient.SqlException';在System.Data.dll中(';附近的“语法不正确”)'&)?,c#,sql,sql-server,exception,ado.net,C#,Sql,Sql Server,Exception,Ado.net,嘿,这是我的代码,这是我得到的错误: 引发异常:中的“System.Data.SqlClient.SqlException” System.Data.dll(“附近语法不正确”)。) 您错过了关键字: 在未指定列名的情况下,不要将insert写入查询。如果出于任何原因向该表中添加新列,则代码将中断。(您可以从一开始就避免这个错误)为什么人们在这里发布代码,却惊慌失措,拒绝学习使用调试器Google是学习SQL语法的一个很棒的免费工具调试器在这里并不能真正帮助您……这是一个SQL语法问题。但是您

嘿,这是我的代码,这是我得到的错误:

引发异常:中的“System.Data.SqlClient.SqlException” System.Data.dll(“附近语法不正确”)。)


您错过了关键字:


在未指定列名的情况下,不要将insert写入查询。如果出于任何原因向该表中添加新列,则代码将中断。(您可以从一开始就避免这个错误)为什么人们在这里发布代码,却惊慌失措,拒绝学习使用调试器
Google是学习SQL语法的一个很棒的免费工具
调试器在这里并不能真正帮助您……这是一个SQL语法问题。但是您需要使用原始SQL命令vs entity framework有什么原因吗?正如Steve在上面指出的那样,这是正确的,但只要数据库中的列按照您期望的顺序排列,它就可以工作。这可能是一个合理的假设。但是,如果您使用EF(以及确保数据库与EDM同步的工具),您可以更容易地发现/防止应用程序代码与数据库架构之间的不匹配。谢谢很多人,我真的错过了。谢谢您的支持
void addMember() 
{
    try 
    {
       //con.Open();
        String EmpID = txtEmpID.Text.ToString().Trim();
        String EmployeeName = txtEmpID.Text.ToString().Trim();
        String UserName = txtUsername.Text.ToString().Trim();
        String UserType = cmbUserType.GetItemText(cmbUserType.SelectedItem);
        String PassWord = txtPassword.Text.ToString().Trim();
        SqlCommand addUser = new SqlCommand("insert into  userDetails(@empID ,@employeeName ,@userName , @userType, @password)", con);
        addUser.Parameters.Add(new SqlParameter("@empID", EmpID));
        addUser.Parameters.Add(new SqlParameter("@employeeName", EmployeeName));
        addUser.Parameters.Add(new SqlParameter("@userName", UserName));
        addUser.Parameters.Add(new SqlParameter("@userType", UserType));
        addUser.Parameters.Add(new SqlParameter("@password", PassWord));

        int x = addUser.ExecuteNonQuery();

        if (x > 0)
        {

            MessageBox.Show("Data Inserted", "User Form", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //con.Close();
    }
    catch (Exception ex) 
    {
        MessageBox.Show("" + ex);
    }
SqlCommand addUser = new SqlCommand("insert into userDetails Values(@empID ," +
                                                              ^^^^
                                    "@employeeName ,@userName , @userType, @password)", con);