How to Insert multiple Tables using Inline Query

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 3256
SqlConnection objSqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Db_Connect"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Bt_Submit_Click(object sender, EventArgs e)
{
string Sqry1 = "Insert into tt1 values('"+ TxtName.Text +"')";
AddRecords(Sqry1);

string Sqry2 = "Insert into tt2 values('" + TxtEmpno.Text + "')";
AddRecords(Sqry2);

string Sqry3 = "Insert into tt3 values(" + Convert.ToInt32(TxtAmount.Text) + ")";
AddRecords(Sqry3);

}
private void AddRecords(string Sqry)
{
objSqlConnection.Open();
SqlCommand sqlcmd = new SqlCommand(Sqry, objSqlConnection);
sqlcmd.ExecuteNonQuery();
objSqlConnection.Close();
}

Comments or Responses

Login to post response