c# - Insert data to master detail tables by a stored procedure -
i'm trying add data master/detail table using stored procedure.
i tried this:
private void ekle() { mysqlcommand cmd = new mysqlcommand("invinputfrompo", bag); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("?trnotes", mysqldbtype.text).value = tb1.text; (int = 0; <= dg1.rows.count - 1; i++) { if (convert.toboolean(dg1.rows[i].cells[0].value) == true) { cmd.parameters.add("?docno", mysqldbtype.varchar).value = dg1.rows[i].cells[9].value.tostring(); cmd.parameters.add("?idpodetails", mysqldbtype.int32).value = convert.toint32(dg1.rows[i].cells[5].value.tostring()); cmd.parameters.add("?idmat", mysqldbtype.int32).value = convert.toint32(dg1.rows[i].cells[6].value.tostring()); cmd.parameters.add("?sn", mysqldbtype.varchar).value = dg1.rows[i].cells[2].value; cmd.parameters.add("?qty", mysqldbtype.decimal).value = convert.todecimal(dg1.rows[i].cells[1].value); //if (dg1.currentrow.cells[4].value.tostring() == "") { cmd.parameters.add("?shelflife", mysqldbtype.date).value = dbnull.value; } //else { cmd.parameters.add("?shelflife", mysqldbtype.date).value = dg1.currentrow.cells[4].value.tostring(); } cmd.parameters.add("?shelflife", mysqldbtype.varchar).value = dg1.rows[i].cells[4].value; } } cmd.connection = bag; cmd.executenonquery(); }
only first parameter "trnotes" added master table, other parameters added detail table.
i made loop way not successful. says defined "docno" (the first parameter in detail table)
could data entry?
when if statement runs second time, tries add docno
list of parameters created on first iteration. docno
added in first iteration, exists.
there couple of ways around this:
- execute stored procedure each row. downside have overhead of additional db calls.
- use user-defined table types. build table in c# , pass parameter stored procedure insert table.
Comments
Post a Comment