参数化更新查询语法错误

时间:2013-10-05 10:26:50

标签: c# winforms ms-access

我正在尝试使用下面的代码更新数据库中的数据,但它给了我语法错误,我在这里做了什么错误

public bool UpdateDrMaster(string title, string FirstName, string Mname, string lastName, string regNo, string speciality, string contactNo1, string contactNo2, string city, string addrss, string pincode, string emailId, string fee_unit, string fee, string DrType, bool displayType)
        {
            bool flag = false;
            try
            {
                string sql = "UPDATE Doctor_Master SET [Title]=@Title,[FirstName]=@FirstName,[MiddleName]=@MiddleName,[LastName]=@LastName,[RegistrationNo]=@RegistrationNo,[Speciality]=@Speciality,[ContactNo_1]=@ContactNo_1,[ContactNo_2]=@ContactNo_2,[City]=@City,[Address]=@Address,[Pincode]=@Pincode,[Email_ID]=@Email_ID,[Fee_Unit]=@Fee_Unit,[Fee]=@,[Type_of_Dr]=@Type_of_Dr,[Display]=@Display,[Hide_Date])";

                cmd = new OleDbCommand(sql, acccon);
                 cmd.Parameters.Add("@Title", title);
                             cmd.Parameters.Add("@FirstName", FirstName);
                             cmd.Parameters.Add("@MiddleName", Mname);
                             cmd.Parameters.Add("@LastName", lastName);
                             cmd.Parameters.Add("@RegistrationNo", regNo);
                             cmd.Parameters.Add("@Speciality", speciality);
                             cmd.Parameters.Add("@ContactNo_1", contactNo1);
                             cmd.Parameters.Add("@ContactNo_2", contactNo2);
                             cmd.Parameters.Add("@City", city);
                             cmd.Parameters.Add("@Address", addrss);
                             cmd.Parameters.Add("@Pincode", pincode);
                             cmd.Parameters.Add("@Email_ID", emailId);
                             cmd.Parameters.Add("@Fee_Unit", fee_unit);
                             cmd.Parameters.Add("@Fee", fee);
                             cmd.Parameters.Add("@Type_of_Dr", DrType);
                             cmd.Parameters.Add("@Display", displayType);
                             cmd.Parameters.Add("@Hide_Date", System.DateTime.Now.ToShortDateString());                            
                cmd.ExecuteNonQuery();
                flag = true;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
            return flag;
        }

1 个答案:

答案 0 :(得分:1)

您的参数无效:

  

,[费用] = @

  

,[Hide_Date])

hide_date后面的右括号可能也错了?

            UPDATE Doctor_Master SET [Title]=@Title
        ,[FirstName]=@FirstName
        ,[MiddleName]=@MiddleName
        ,[LastName]=@LastName
        ,[RegistrationNo]=@RegistrationNo
        ,[Speciality]=@Speciality
        ,[ContactNo_1]=@ContactNo_1
        ,[ContactNo_2]=@ContactNo_2
        ,[City]=@City
        ,[Address]=@Address
        ,[Pincode]=@Pincode
        ,[Email_ID]=@Email_ID
        ,[Fee_Unit]=@Fee_Unit
        ,[Fee]=@
        ,[Type_of_Dr]=@Type_of_Dr
        ,[Display]=@Display
        ,[Hide_Date])";