0

i am creating a gridview at runtime like this

DataTable dt = new DataTable();


           DataRow dr=null;
           if (gdvItem_Indent_List.Rows.Count == 0)
           {
               dt.Columns.Add("ItemType", System.Type.GetType("System.String"));
               dt.Columns.Add("Cost", System.Type.GetType("System.String"));
               dt.Columns.Add("Quantity", System.Type.GetType("System.String"));
               dr = dt.NewRow();
               dr["ItemType"] = ddlItem.SelectedItem.Text;
               dr["Cost"] = txtEstimateCost.Text;
               dr["Quantity"] = txtReqQty.Text;
               dt.Rows.Add(dr);
               ViewState["ItemData"] = dt;
           }
           else
           {
               dt = (DataTable)ViewState["ItemData"];
               dr = dt.NewRow();
               dr["ItemType"] = ddlItem.SelectedItem.Text;
               dr["Cost"] = txtEstimateCost.Text;
               dr["Quantity"] = txtReqQty.Text;
               dt.Rows.Add(dr);
           }
           dt.AcceptChanges();
           if (dt.Rows.Count > 0)
           {
              
                   gdvItem_Indent_List.DataSource = dt;
                   gdvItem_Indent_List.DataBind();
               
           }
           ViewState["ItemData"] = dt;

now i need to insert the data from datatable to database how can i do that.
i have no clue to do that
please help.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by pinkygirl
0

Try using DataGrid control instead of DataTable. It is much simpler

Edited by pinkygirl: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.