Sunday, March 11, 2012

Connection Help!

I can't connect to my sql server 2000 database from Visual Studio using vb.net.

I'm trying to use the gotdotnet quickstart tutorials but they just throw dumb errors all the time ...

For example, I'm trying to perform a simple SELECT query

Dim myConnection As New SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes")
Dim myCommand As New SqlDataAdapter("select * from Authors", myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds, "Authors")

My error - "Too many arguments to 'public sub New()' " for the SQLConnection.

I then tried this


Dim dbconn As New SqlClient.SqlConnection
dbconn.ConnectionString = "server=(local);Database=northwind;User ID=sa;trusted_connection=true"
dbconn.Open()

Dim myCommand As New SqlDataAdapter("select top 1 categoryname from Categories", dbconn)

Dim ds As New DataSet
myCommand.Fill(ds, "Authors")

Now this seems to work but I'm not sure if I need to bind the SELECT information to a textbox or something (response.write(ds) doesn't work.)

Any help appreciated as this is getting bloody annoying!

CheersThe quickest way to see all the data is to open the web form in design view and drop a DataGrid control from the Toolbox window onto the form. Then switch back to code view and add the follwing lines after the Fill:


DataGrid1.DataSource = ds
DataGrid1.DataBind()

No comments:

Post a Comment