c# - How to save all the rows of RadGrid at once into SQL Database on a button click along with another data which is outside of RadGrid -


there radgrid (say "radgridbill") in have 4 columns:

  1. id
  2. billing id
  3. cost
  4. business unit

above radgrid's (radgridbill) data bind using "billing table".

i have show radgrid (say "radgridinvoice") on web page,with below columns:

  1. id
  2. invoiceid
  3. billingid
  4. cost
  5. business unit
  6. status
  7. invoice number

there table named "invoice table" in database, above columns.

there button outside radgrid's named "generate" button.

now, requirement is: have save records of "radgridbill" using billing table (all rows) database "invoice table" respective columns (i.e., billing table cost column data should save in invoice table cost column) along "status"; on "generate" button click

also, "status" should saved "draft" when user click on "generate" button, database "invoice table".

this data has save @ once invoice table.

please let me know how achieve above scenario.

i new telerik in advance.

check out below code...

string invoiceid; string billingid; string cost; string businessunit; string status; string invoicenumber; public static string connectionstring = configurationmanager.appsettings("connectionstring"); public sqlconnection sqlconnection = new sqlconnection(connectionstring); public sqldataadapter sqldataadapter = new sqldataadapter();  public sqlcommand sqlcommand = new sqlcommand(); private void insertgrd() {     foreach (griddataitem itm in radgrid1.items) {         invoiceid = itm["invoiceid"].text;         billingid = itm["billingid"].text;         cost = itm["cost"].text;         businessunit = itm["businessunit"].text;         status = itm["status"].text;         invoicenumber = itm["invoicenumber"].text;         try {             //open sqlconnection             sqlconnection.open();             //update query insert database             string insertquery = "insert invoice values('" + invoiceid + "','" + billingid + "','" + cost + "','" + businessunit + "','" + status + "','" + invoicenumber + "')";             sqlcommand.commandtext = insertquery;             sqlcommand.connection = sqlconnection;             sqlcommand.executenonquery();             //close sqlconnection               sqlconnection.close();         } catch (exception ex) {             interaction.msgbox("unable insert. reason: " + ex.message);          }      } } 

call above function in button_click event...

hope helps...


Comments