命令执行期间发生致命错误

时间:2015-05-04 14:32:27

标签: c# mysql

我在C#中执行update命令时遇到致命错误我正在使用mysql数据库。一切都很好,如插入命令和删除命令,但当我要更新记录时,它显示错误,这是命令执行期间的致命错误。 请帮我。

public bool UpdateSupplierDetails(string supplierName, string tinNo, string panNo, string serviceTaxNo, string mobileNo, string phoneNo, string fax, string emailID, string website, string address, string id)
        {//Initialising the connection object
            using (MySqlConnection con = new MySqlConnection(config.connectionString))
            {
                try
                {
                    //checking connection state 
                    if (con.State == System.Data.ConnectionState.Closed)
                        con.Open();//if connection state is closed then open the connection
                    //defining mysql command object to select the query and assign the open connection to the mysqlcommand object
                    using (MySqlCommand cmd = new MySqlCommand("UPDATE tb_supplier SET suppliername = @suppliername, tinno = @tinno, panno = @panno, servicetaxno = @servicetaxno, mobileno = @mobileno, phoneno = @phoneno, faxno = @faxno, emailid = @emailid, website = @website, address = @address WHERE id = @id;", con))
                    {
                        cmd.Parameters.AddWithValue("@suppliername", supplierName.Trim());//Bind supplier name
                        cmd.Parameters.AddWithValue("@tino", tinNo.Trim());//Bind supplier tin no.
                        cmd.Parameters.AddWithValue("@panno", panNo.Trim());//Bind supplier pan no.
                        cmd.Parameters.AddWithValue("@servicetaxno", serviceTaxNo.Trim());//Bind supplier service tax no.
                        cmd.Parameters.AddWithValue("@mobileno", mobileNo.Trim());//Bind supplier mobile no.
                        cmd.Parameters.AddWithValue("@phoneno", phoneNo.Trim());//Bind supplier phone no.
                        cmd.Parameters.AddWithValue("@faxno", fax.Trim());//Bind supplier fax no.
                        cmd.Parameters.AddWithValue("@emailid", emailID.Trim());//Bind supplier email id
                        cmd.Parameters.AddWithValue("@website", website.Trim());//Bind supplier website
                        cmd.Parameters.AddWithValue("@address", address.Trim());//Bind supplier address
                        cmd.Parameters.AddWithValue("@id", id);//Bind customer ID
                        cmd.ExecuteNonQuery();//Executing assigned query
                        cmd.Parameters.Clear();//clear parameters
                        return true;//return true if query executed successfully
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return false;//return false if something goes wrong
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

我遇到了问题。 我错了拼写tinno

原始代码

NULL

修改后的代码

cmd.Parameters.AddWithValue("@tino", tinNo.Trim());//Bind supplier tin no.

现在命令已成功执行。