sql server - Visual C# SQL statement won't insert into database -


i trying insert values sql table. id in database cannot auto_increment use max , +1. not code not make new id, isn't inserting anything table.

even in debugger there no errors or warnings, isn't showing in database itself..

here code:

using system; using system.collections.generic; using system.data; using system.data.sqlclient; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.windows; using system.componentmodel; using system.drawing; using system.text;   namespace webapplication2 { public partial class webform1 : system.web.ui.page {      protected void page_load(object sender, eventargs e)     {      }      protected void buttonclick(object sender, eventargs e){            using (var sqlconnection1 = new sqlconnection("data  source=server; initial catalog = metal; integrated  security = true"))         {             sqldataadapter cmd = new sqldataadapter();              using (var insertdata = new sqlcommand("insert apptin  (controlnumber, carriername, expectednumofpieces, expectedweight) values  (@carrierselectinput,  @piececountinput, @weightinput)")             {                    sqlcommand generateapptnum = new sqlcommand();                 view appnumview = new view();                  insertdata.connection = sqlconnection1;                  string carrierselectinput = dropdownlist1.text;                 string piececountinput = textbox1.text;                 string weightinput = textbox2.text;                  insertdata.parameters.add("@carrierselectinput",  carrierselectinput.varchar);                 insertdata.parameters.add("@piececountinput",  piececountinput.int);                 insertdata.parameters.add("@weightinput",  weightinput.int);                  cmd.insertcommand = insertdata;                  sqlconnection1.open();                 insertdata.executenonquery();                 generateapptnum.executenonquery();                 sqlconnection1.close();             }         }          }     } } 

edit: have tried running sql db , gave error, changed it(updated in code) puts in @ id=0...

i know have committed plan, but, feel have point out that, due sub select max id value in query, insert statement has potential slower normal insert.

if planning on inserting large number of rows or creating api use throughout code highly recommend either adjusting column definition identity column or consider using a sequence generate ids.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -