I don't think so. You should close your connection
when you're done with it. It's not exactly difficult
to open one.
I'm not sure what you mean by this:
I have made a new variable and set its type to
System.Data.SqlClient.SqlConnection however i dont know
what to set its value to?
You don't really set its value to anything, you just open it.
Here's an example of how to use a connection and command object to fill a
datatable.
This disposes of the connection when it hits the
"End Using".
-------------------
Dim dt as DataTable
Using cnn As New SqlConnection(My.Settings.ProductConnectionString)
cnn.Open()
'define the command
Dim cmd As New SqlCommand
cmd.Connection = cnn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "ProductRetrieveByID_sp"
cmd.Parameters.AddWithValue("@productid", 1)
'define the data adapter and fill the data table
Dim da As New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
End Using
return dt
-----------------
Robin S.
--------------------------
"jimmy" <ja**************@tiscali.co.ukwrote in message
news:11*********************@j44g2000cwa.googlegro ups.com...
Thanks alot for that, that should come in really useful in my
application. I never knew about these settings! Just out of interest is
there any way i can store the actual connection itself in there?
I have made a new variable and set its type to
System.Data.SqlClient.SqlConnection however i dont know what to set its
value to? Can i make a connection this way or do i need to create a new
connection each time using the connection string?
Thanks
James