I have Category table like below
C_ID Category
1 PEN
2 BOOK
Then here is Item table
S_ID ItemName C_ID
-------------------------------
1 2
2 1
So the challenge is when inserting catgory i want to insert the catgory C_ID into C_ID column of Item table code
protected void btnsubmit2_Click(object sender, EventArgs e)
{
int inserted = 0;
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = str;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.CommandText = "INSERT INTO ItemCategory (Category) VALUES(@Category)";
cmd.Parameters.AddWithValue("@Category", txtcategory.Text);
con.Open();
inserted = cmd.ExecuteNonQuery();
con.Close();
string message = string.Empty;
{
lblMessage2.Visible = true;
lblMessage2.Text = "Data Submitted Successfully";
}
Panel pn = (Panel)btnsubmit.FindControl("Panel2");
pn.Visible = true;
}
}