Re: Connecting to sql server
From: Cowboy \(Gregory A. Beamer\) [MVP] (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 07/09/04
- Next message: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: Strings.. Objects or not???"
- Previous message: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: Strings.. Objects or not???"
- In reply to: don: "Connecting to sql server"
- Next in thread: don: "Re: Connecting to sql server"
- Reply: don: "Re: Connecting to sql server"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 9 Jul 2004 13:37:36 -0500
For the record: I hate Visual Basic .NET Standard.
Having said that, you should be able to do what you desire by moving away
from the "automagic" tools (wizards). Here is some code that might help:
Private Function GetData() As DataSet
'Change the server name, database and user info
'for your DB
Dim connStr As String = "Server=(local);Database=" & _
"pubs;UID=sa;PWD=;"
Dim sql As String = "SELECT * FROM Authors"
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand(sql, conn)
'Name here should be a friendly name
'for your dataset
Dim ds As New DataSet("nameHere")
Dim da As New SqlDataAdapter(cmd)
'Change FriendlyName to a table name for your
'data.
da.TableMappings.Add("Table", "FriendlyName")
Try
conn.Open()
da.Fill(ds)
Finally
If conn.ConnectionState = _
ConnectionState.Open Then
conn.Close()
End If
conn.Dispose()
End Try
End Function
You can test this by binding a DataView to this routine:
DataView1.DataSource = GetData()
DataView1.DataBind()
-- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************ Think Outside the Box! ************************************************ "don" <don.ns@ns.mweco.com> wrote in message news:UbudnTLHVuMyR3PdRVn-iQ@sigecom.net... > If this is not correct group, please point me in right direction. > > I am very new to vb.net. I purchased the standard version of Visual > Basic.net. > > I am trying to get a row of data from a SQL Server on our network. > > I have gone to tools > connect to databases and set up a connection to > our sql server. When I test the connection, it says "Test conection > succeeded". > > When I click ok in the Data Link Properties Window which just validated the > connection, I am asked for password to the server and I respond, then I get > an error message as follows: > > Unable to connect to database. > It is only possible to connect to SQL Server Desktop Engine databases and > microsoft access databases with this version of Visual Studio. > > Do I need to purchase something else in order to do this. This small > project is the reasonn I purchased the Visual Basic.Net software in the > first place. It said I could connect to a wide range of data sources. > > Thanks in advance for any help.
- Next message: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: Strings.. Objects or not???"
- Previous message: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: Strings.. Objects or not???"
- In reply to: don: "Connecting to sql server"
- Next in thread: don: "Re: Connecting to sql server"
- Reply: don: "Re: Connecting to sql server"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|