It it possible to insert data into two table simultaneously? In my current page, there is only one command that insert data only in one table,CarTab.
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
SqlCommand cmd = new SqlCommand("Insert into CarTab(Manufacture,Model,Plate,Color,Year,Service,Roadtax) Values (@manufactures,@models,@plates,@colors,@years,@services,@roadtaxs)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@manufactures", Label1.Text);
cmd.Parameters.AddWithValue("@models", Label2.Text);
cmd.Parameters.AddWithValue("@plates", Label3.Text);
cmd.Parameters.AddWithValue("@colors", Label4.Text);
cmd.Parameters.AddWithValue("@years", Label5.Text);
cmd.Parameters.AddWithValue("@services", Label6.Text);
cmd.Parameters.AddWithValue("@roadtaxs", Label7.Text);
conn.Open();
cmd.ExecuteNonQuery();
If I want to put another table, TempTab what is the command? Thanks.
There are many possible solution to your answer. First, I would suggest that you create a
TRIGGERon every insert on tableCarTab.Second, why not change the
CommandTextof your command object and callExecuteNonQuery()again?and Lastly create a
Stored Procedureand in your C# code,