OB1Canobie
asked on
Connecting to SQL Server with ViB Form
I have an SQL Server database "RCM" which has a table "data_live". I have a visual basic application that has a form "worklist" which will display all data in the table. Can anyone help me complete this task? The form is a datagrid view. Thanks.
http://www.vbdotnetheaven.com/UploadFile/mahesh/DataGridSamp04232005050133AM/DataGridSamp.aspx should get you close. I'll gladly answer any follow-ups.
Assuming you've named your datagrid as grd, and you want to load data after you click a button Command1, this code snippet will work just fine. Make sure you put a reference to Microsoft ActiveX Data Objects
Private Sub Command1_Click()
On Error GoTo errhan
Dim con As New ADODB.Connection
Dim rec As New ADODB.Recordset
con.Open "DRIVER=SQL Server;SERVER=192.168.0.57\SQLEXPRESS;PASSWORD=dynamite;UID=MyUserName;DATABASE=RCM"
rec.Open "SELECT * FROM data_live", con, adOpenStatic, adLockOptimistic
Set grd.DataSource = rec
Exit Sub
errhan:
MsgBox Err.Description
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Great resource. Thanks.