参数化更新查询在c#中不起作用

时间:2017-04-13 10:59:52

标签: c# sql-server parameterized-query

我正在尝试更新详细信息,但查询无效。客户端ID是自动生成的。 这是我的代码

try
        {
            con.Open();
            SqlCommand updatecmd = new SqlCommand();
            updatecmd.CommandType = CommandType.Text;
           // long client_id = CreateID();
            updatecmd.CommandText= "UPDATE client_info SET companyname = @companyname, url = @url, industry = @industry, contactperson1 = @contactperson1, contactperson2 = @contactperson2, designation = @designation, fax = @fax, phone = @phone, mobile = @mobile, emailid1 = @emailid1, emailid2 = @emailid2, baddress = @baddress, bcity = @bcity, bstate = @bstate, bzipcode = @bzipcode, bcountry = @bcountry, regaddress = @regaddress, regcity = @regcity, regstate = @regstate, regzipcode = @regzipcode, regcountry = @regcountry WHERE client_id = @client_id";
           // updatecmd.Parameters.AddWithValue("@client_id", client_id);
            updatecmd.Parameters.AddWithValue("@companyname", txtcompanyname.Text);
            updatecmd.Parameters.AddWithValue("@url", txturl.Text);
            updatecmd.Parameters.AddWithValue("@industry", drpindustry.Text);
            updatecmd.Parameters.AddWithValue("@contactperson1", txtcontactperson1.Text);
            updatecmd.Parameters.AddWithValue("@contactperson2", txtcontactperson2.Text);
            updatecmd.Parameters.AddWithValue("@designation", txtdesignation.Text);
            updatecmd.Parameters.AddWithValue("@fax", txtfaxnumber.Text);
            updatecmd.Parameters.AddWithValue("@phone", txtphone.Text);
            updatecmd.Parameters.AddWithValue("@mobile", txtmobile.Text);
            updatecmd.Parameters.AddWithValue("@emailid1", txtemailid1.Text);
            updatecmd.Parameters.AddWithValue("@emailid2", txtemailid2.Text);
            updatecmd.Parameters.AddWithValue("@baddress", txtbaddress.InnerText);
            updatecmd.Parameters.AddWithValue("@bcity", txtbcity.Text);
            updatecmd.Parameters.AddWithValue("@bstate", txtbstate.Text);
            updatecmd.Parameters.AddWithValue("@bzipcode", txtbzipcode.Text);
            updatecmd.Parameters.AddWithValue("@bcountry", bddlCountries.Text);

updatecmd.Parameters.AddWithValue("@regaddress",txtraddress.InnerText);
            updatecmd.Parameters.AddWithValue("@regcity", txtrcity.Text);
            updatecmd.Parameters.AddWithValue("@regstate", txtrstate.Text);

          updatecmd.Parameters.AddWithValue("@regzipcode",txtrzipcode.Text);
            updatecmd.Parameters.AddWithValue("@regcountry", 
            rddlCountries.Text);
            updatecmd.ExecuteNonQuery();

它没有显示错误和异常,但数据没有存储在DB中。

0 个答案:

没有答案