小编phy*_*hyx的帖子

System.Data.dll中的"System.Data.SqlClient.SqlException"("语法不正确").")?

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

抛出异常:System.Data.dll中的'System.Data.SqlClient.SqlException'("'语法不正确')'.")


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("" + …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server ado.net exception

2
推荐指数
1
解决办法
842
查看次数

标签 统计

ado.net ×1

c# ×1

exception ×1

sql ×1

sql-server ×1