Hi,
This program below works fine; however, I have a question. I am using two different connections one to CommandSqlServer and another to CommandSqlServer1.
Am I right this means to 3 commands I need 3 connections and so on - (of course all of them nested)
Or am I wasting resource in case how can I do (Because if I use just one I got an exception).
//Connection string for SqlServer 2005
ConnectionSqlServer = new SqlConnection();
ConnectionSqlServer1 = new SqlConnection();
...stuff
//Command
CommandSqlServer = new SqlCommand(stringCommandSqlServer, ConnectionSqlServer);
CommandSqlServer1 = new SqlCommand(stringCommandSqlServer, ConnectionSqlServer1);
...stuff
//Command 1
CommandSqlServer.CommandText = "SELECT 1 From dummy ";
// Execute
DtReaderSqlServer = CommandSqlServer.ExecuteReader();
while (DtReaderSqlServer.Read() )
{
// Command 2
CommandSqlServer1.CommandText = "update table x
values(" + DtReaderSqlServer.GetValue(1).ToString() + " ) "
//Execute Command 2
CommandSqlServer1.ExecuteNonQuery();
}
Cheers,
Visual Studio Express Editions1
|