我有一個非強制電話文本框字段,數據類型爲int。如果我將電話域留空並提交表單,則電話號碼欄將在數據庫中存儲0(零)。我在更新時遇到問題: ,當手機爲'0'時更新,各行未更新。 我是否需要將手機的默認值設置爲空?如果是這樣請解釋。當0(零)值存儲爲c#中的空字段時無法更新
這裏是我的更新查詢
cmd.CommandText = "UPDATE client_final 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";
cmd.Parameters.AddWithValue("@client_id", txtClientId.Text);
cmd.Parameters.AddWithValue("@companyname", txtcompanyname.Text);
cmd.Parameters.AddWithValue("@url", txturl.Text);
cmd.Parameters.AddWithValue("@industry", drpindustry.Text);
cmd.Parameters.AddWithValue("@contactperson1", txtcontactperson1.Text);
cmd.Parameters.AddWithValue("@contactperson2", txtcontactperson2.Text);
cmd.Parameters.AddWithValue("@designation", txtdesignation.Text);
cmd.Parameters.AddWithValue("@fax", txtfaxnumber.Text);
cmd.Parameters.AddWithValue("@phone", txtphone.Text);
cmd.Parameters.AddWithValue("@mobile", txtmobile.Text);
cmd.Parameters.AddWithValue("@emailid1", txtemailid1.Text);
cmd.Parameters.AddWithValue("@emailid2", txtemailid2.Text);
cmd.Parameters.AddWithValue("@baddress", txtbaddress.InnerText);
cmd.Parameters.AddWithValue("@bcity", txtbcity.Text);
cmd.Parameters.AddWithValue("@bstate", txtbstate.Text);
cmd.Parameters.AddWithValue("@bzipcode", txtbzipcode.Text);
cmd.Parameters.AddWithValue("@bcountry", bddlCountries.Text);
cmd.Parameters.AddWithValue("@regaddress", txtraddress.InnerText);
cmd.Parameters.AddWithValue("@regcity", txtrcity.Text);
cmd.Parameters.AddWithValue("@regstate", txtrstate.Text);
cmd.Parameters.AddWithValue("@regzipcode", txtrzipcode.Text);
cmd.Parameters.AddWithValue("@regcountry", rddlCountries.Text);
當你更新? –
@Dheeraj Sharma錯誤沒有顯示,但當點擊按鈕時,所有字段變爲空白。 – Nirmala
有可能代碼中存在一些錯誤而不是查詢,因爲在任何字段中都有0不會停止執行查詢,請詳細說明您的問題。 –