July 10, 2009 at 11:49 pm
I am trying to load data from SQL 2005 and I'm gettiing an
error in VB 2008 that the ConnectionString property is not initialized.
I don't know how to correct this.
It worked fine on the main form but on the second form it doesn't work.
My vb code is:
'* Configure data adaptor and fill data set
sqlDABC.SelectCommand = sqlCmd
sqlDABC.Fill(dsBC, "Supplier")
Any ideas?
July 11, 2009 at 3:42 am
Hi
You need at least two objects to get data from database:
* A SqlConnection which specifies the server and database
* A SqlDataAdapter which gets the connection and a statement or a SqlCommand
Since those objects work with un-managed resources I suggest to work with "Using" blocks:
' Destination table
Dim table As New DataTable
' Connection to server
Using cn As New SqlConnection("Server=yourServer;Database=YourDb;Integrated Security=SSPI")
cn.Open()
' Adapter to get data
Using adap As New SqlDataAdapter("SELECT * FROM YourTable", cn)
adap.Fill(table)
End Using
End Using
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply