开发者

transfer data from a gridview to a database

开发者 https://www.devze.com 2023-02-05 14:36 出处:网络
I have this code private void BindSecondaryGrid() { DataTable dt = (DataTable)ViewState[\"SelectedRecords1\"];

I have this code

private void BindSecondaryGrid()
{
    DataTable dt = (DataTable)ViewState["SelectedRecords1"];
    gridview3.DataSource = dt;
    gridview3.DataBind(); 
}

The selected records from开发者_高级运维 the gridview2 are saved there ViewState["SelectedRecords1"].The columns are id, name, quantity, total. Then these records are saved in gridview3 with

gridview3.DataSource = dt;
gridview3.DataBind();

Now i would like to get these values from gridview3 and store them in a table in my database with same columns of course.Is there a way to do that?


Is the question about "how to get to the data" or "how to write to DB"?

I'll try with "how to get to the data" :-)

You can loop the rows of "dt" using:

foreach(DataRow oRow in dt.Rows)
{
  int id = Convert.ToInt32(oRow["id"]);
  string name = oRow["name"].ToString();
  int quantity = Convert.ToInt32(oRow["quantity"]);
  int total = Convert.ToInt32(oRow["total"]);
}

Then you need to setup a DB connection and add the values.

0

精彩评论

暂无评论...
验证码 换一张
取 消