I tried to search for what I am looking for, but I guess I don't know the best way to phrase it, so I was hoping someone could help me out.
I want to create/open a Connection to a database, get some kind of DataReader/DataAdapter or something filled with data, then close the Connection so that I can reuse it.
Here's an example, but if I don't translate my C# to VB.NET perfectly please forgive me.
I basically want to reuse the connection over so I don't have to create multiple Connections, since you can't reuse a Connection once it is tied to a command/datareader. The Using statement will handle the cleanup for the Connection and Commands.
I am probably wrong about the above statements, but hey I am trying to learn.
Any help would be appreciated.
Thanks,
CT
I want to create/open a Connection to a database, get some kind of DataReader/DataAdapter or something filled with data, then close the Connection so that I can reuse it.
Here's an example, but if I don't translate my C# to VB.NET perfectly please forgive me.
VB.NET:
Using conn As New SqlConnection("myconnectionstring")
conn.Open()
Using cmd1 As New SqlCommand("mycommandtext1", conn)
' Open DataReader or DataAdapter or something
' Disconnect cmd from conn so conncan be reused
' Do some processing
End Using
conn.Open()
Using cmd2 As New SqlCommand("mycommandtext2", conn)
' Open DataReader or DataAdapter or something
' Disconnect cmd from conn so conncan be reused
' Do some processing
End Using
End Using
I basically want to reuse the connection over so I don't have to create multiple Connections, since you can't reuse a Connection once it is tied to a command/datareader. The Using statement will handle the cleanup for the Connection and Commands.
I am probably wrong about the above statements, but hey I am trying to learn.
Any help would be appreciated.
Thanks,
CT