Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to SQL Server Database via VB.Net

Status
Not open for further replies.

avbnet

Programmer
Feb 5, 2003
5
TR
I want to connect SQL Server database during runtime.User will input "database","server","password" and "UserID" via a form.I'm using sql server 2000 and VB.Net Beta 2.I have written some script to connect to database.First, I tried to import ADODB but i encountered an error message saying "ADODB" not defined.And then i tried to import SQLDMO object.Again the same message.Is the problem since i use VB.Net Beta edition?I aim to show records of a table in a grid.Table will be chosen by user after the connection is established.If anybody can help me, i would be very glad.Thank you.
 
Hello,
Try using the Data-Adapter and the Dataset object in vb.net ...
walkthru's are provoded with MSDN ...they r really very simple ...
 
Imports System.Data.SqlClient


'declare your connection,cmd, dataset, and adapter
Dim conn As New SqlConnection()
Dim ds As New DataSet()
dim cmd As New SqlCommand()

'provide connection information
conn.ConnectionString = "Provider=SQLOLEDB.1;Password="YourPassword";Persist Security Info=True;User ID="YourUserName";Initial Catalog="YourDatabase";Data Source="YourServer""

'open your connection
conn.Open()
'set command properties
cmd.CommandType = CommandType.Text
cmd.Connection = conn

'set your query text(SQL)
cmd.CommandText = "SELECT STUFF FROM THINGS"
'populate the dataset
Dim da As New SqlClient.SqlDataAdapter(cmd)
da.Fill(ds)
'your dataset now contains your query result. you can parse it or bind it to a control


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top