I am creating a project in which I need to run 2-3 SQL commands in a single SQL connection. Here is the code I have written:
SqlConnection con = new SqlConn
I have not tested , but what the main idea is: put semicolon on each query.
SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();
connection.ConnectionString = connectionString; // put your connection string
command.CommandText = @"
update table
set somecol = somevalue;
insert into someTable values(1,'test');";
command.CommandType = CommandType.Text;
command.Connection = connection;
try
{
connection.Open();
}
finally
{
command.Dispose();
connection.Dispose();
}
Update: you can follow Is it possible to have multiple SQL instructions in a ADO.NET Command.CommandText property? too