sql server - unable to update when 0(zero) value is stored for empty fields in c# -
i have non mandatory phone textbox field , datatype int. if leave phone field blank , submit form, phone column stored 0(zero) in database. facing issue update: while updating when phone '0' respective row not updated. need set default value of phone null? if please explain.
here update query
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 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);
as datatype phone column int, , default value int 0. please specify column nullable in database should work.
Comments
Post a Comment