c# - Pass multiple values to SQL insert statement -


i have web form has 23 textbox's , need pass function, has sql command insert values of 23 textbox table..

is there better way using dataset , sqldataadapter? becuase if not need pass 23 vlues in function like

//function insert textbox values table

public int createrecord(val1,val2,val3,....val23) {    string query = "insert tablename values (.23 values...)";    sqlcommand command = new sqlcommand(query,connectionstring); .. } 

please suggest me atleast method or give link can solve problem..

if inserting record , 23 values necessary, there's not better way.

however, it'd better use stored procedure , pass parameters stored procedure instead of using hardcoded sql in application, bad idea.

something this:

sqlcommand cmd  = new sqlcommand("yourspname", conn); cmd.commandtype = commandtype.storedprocedure;  // add parameters sp needs cmd.parameters.add(new sqlparameter("@parm1", parm1value)); cmd.parameters.add(new sqlparameter("@parm2", parm2value)); . .  // execute sp cmd.executenonquery(); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -