sql server - How to pass NULL Value to Stored Procedure Through C# -


i have multiple textboxes , want allow user leave empty instead of giving error

sqlparametercollection accepts non-null sqlparameter type objects.

what use inserting data in data_access_layer class

public void executecommand(string data, sqlparameter[] param)     {         sqlcommand sqlcmd = new sqlcommand();         sqlcmd.commandtype = commandtype.storedprocedure;         sqlcmd.commandtext = data;         sqlcmd.connection = sqlconnection;           if (param != null)         {              sqlcmd.parameters.addrange(param);         } 

the main form code:

namespace m_weight_system.presentation_layer {     public partial class main : form     {         bussiness_layer.cls_data dta = new bussiness_layer.cls_data();         public main()         {             initializecomponent();         }          private void bsave_click(object sender, eventargs e)         {             try             {               dta.add_data(tid.text, tnumber.text, tclient.text, tdriver.text, convert.toint32(tfirst.text), convert.toint32(tsecond.text), convert.toint32(rt2.text), tdate1.text,tcity.text, ttype.text,tdate2.text);                 messagebox.show("success");                 bedit.enabled = true;                 newtoolstripmenuitem.enabled = true;                 printtoolstripmenuitem.enabled = false;             }             catch             {                 messagebox.show("problem !");             }         }          private void bedit_click(object sender, eventargs e)         {             try             {                 dta.update_data(tid.text, tnumber.text, tclient.text, tdriver.text, convert.toint32(tfirst.text), convert.toint32(tsecond.text), convert.toint32(rt2.text), tdate1.text, tcity.text, ttype.text, tdate2.text);                 messagebox.show("success");              }             catch             {                 messagebox.show("problem !");             }          }         } } 

you can try command.parameters.add("@param", dbnull.value); or can set defaults null in proc , don't have explicitly pass null proc.

create proc ..dbo.proc ( @param1 int =null, @param2 varchar(40) = null ...) 

also, if have send null app use dbnull.value


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -