Can I use two command object with one open connection in one procedure at VB.NET?
+1
A:
Yes you can. As long as you don't close the connection between commands, it'll work fine.
This is a C# example, but I'm sure you can work it out:
using (SqlConnection cn = new SqlConnection("Connection String"))
{
SqlCommand cmd1 = new SqlCommand("Command1", cn);
cmd1.CommandType = CommandType.StoredProcedure;
SqlCommand cmd2 = new SqlCommand("Command2", cn);
cmd2.CommandType = CommandType.StoredProcedure;
cn.Open();
// Execute cmd1
// Execure cmd2
}
GenericTypeTea
2009-11-05 09:30:49
Thanks you a lot!
RedsDevils
2009-11-05 09:34:05
Don't forget to vote up and accept if it works ;)
GenericTypeTea
2009-11-05 09:34:30
I would like to vote but my reputation is under 15. :P
RedsDevils
2009-11-05 09:54:05
Thanks RedsDevils :)
GenericTypeTea
2009-11-05 10:12:43
+2
A:
Example; kinda pseudo but you should get the concept.
dim cnn as connection
dim cmd as command
dim cmd2 as command
dim str1 as string
dim str2 as string
cnn.open
cmd.connection = cnn
cmd.command = str1
cmd.execute
cmd2.connection = cnn
cmd2.command = str2
cmd2.execute
cnn.close
Pace
2009-11-05 09:35:15