Getting data from SQL Table
 
- using (var con = new SqlConnection(constr))  
- {  
- string query = "select * from higher_office";  
- using (var cmd = new SqlCommand(query, con))  
- {  
- using (var sda = new SqlDataAdapter())  
- {  
- cmd.Connection = con;  
- sda.SelectCommand = cmd;  
- using (TableData)  
- {  
- TableData.Clear();  
- sda.Fill(TableData);  
- }  
- }  
- }  
- }  
aspx fetched data and new Textbox for inputing values corresponding to higher office
- <% for (var data = 0; data < TableData.Rows.Count; data++)  
- {  
- %>  
- <tr>  
- <td>  
- <%=TableData.Rows[data]["higher_office_ID"]%>  
- </td>  
- <td>  
- <%=TableData.Rows[data]["higher_office_Name"]%>  
- </td>  
- <td>  
- <asp:TextBox ID="TextBox1" runat="server" width="150px" ></asp:TextBox>  
- </td>  
- </tr>  
- <% } %>  
trying to insert as follows but not excute
 
- using (SqlConnection con = new SqlConnection(constr))  
- {  
- con.Open();  
-   
- for (int i = 1; i <= rowCount; i++)  
- {  
- SqlCommand cm = new SqlCommand("insert into item_distribution (sector,quantity) values('"+ id +"','"+ amount+"')",con);  
- try  
- {  
- cm.ExecuteNonQuery();  
- RoleMessage.Text += "Successfully inserted";  
- RoleMessageDIV.Style["display"] = "block";  
- }  
- catch(Exception ex )  
- {  
- RoleMessage.Text +="Not inserted "+ex;  
- RoleMessageDIV.Style["display"] = "block";  
- }  
- }  
- con.Close();  
- }