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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.