A table is created in the database with a customer name (which is entered in a TextBox
). The fields of the table created are the items in the ListBox
. Like:
com = new SqlCommand("CREATE TABLE " + Label6.Text + " (Locations nvarchar(20), " + ListBox3.Items[0].ToString().Trim() + " nvarchar(5))", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
for (int i = 1; i <= ListBox3.Items.Count-1; i++)
{
com = new SqlCommand("ALTER TABLE " + Label6.Text + " ADD " + ListBox3.Items[i].Text.Trim() + " nvarchar(5)", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
I am further displaying this table using GridView
. Like:
SqlCommand com = new SqlCommand("SELECT * FROM " + Label6.Text + "", con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
The asp code for GridView is :
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
Hence, I want the first column to be readonly.
I want to edit the GridView
and update the customer(referring to Label6.Text) table in the database. Note: I want the GridView to accept only integers.
The image of my database table and the Gridview is shown in the following link. Kindly help. Thank you.