This is the Code i have and it works well when choose one connection string in Combobox
How can i execute same SQL query in multiple connections with one button click not one by one??
public string connstring = "";
private void cmbSrv_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbSrv.SelectedIndex == 0)
{
connstring = @"Data Source=tcp:10.1.0.100;Initial Catalog=Database1;User ID=user;Password=pass;MultipleActiveResultSets=true;";
}
else if (cmbSrv.SelectedIndex == 1)
{
connstring = @"Data Source=tcp:10.0.0.100;Initial Catalog=Database2 ;User ID=user;Password=pass;MultipleActiveResultSets=true;";
}
}
private void btnKonfirm_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(connstring))
{
SqlCommand cmd1 = new SqlCommand();
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
SqlCommand command1 =
new SqlCommand("DELETE FROM TABLE1 WHERE ID="+textbox1+"", connection);
command1.ExecuteNonQuery();
connection.Close();
}
}