如何在vb中对SQL SERVER进行条件查询并将结果显现在data grid的控件中
1个回答
展开全部
工程 引用 microsoft activex database object 2.8
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Private Sub Command1_Click()
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=库名;Data Source=127.0.0.1", "用户名", "密码"
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM 表名", conn, adOpenKeyset, adLockOptimistic
rst.MoveFirst
Do While Not rst.EOF
Debug.Print rst.Fields(0) & rst.Fields(1)
rst.MoveNext
Loop
End Sub
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Private Sub Command1_Click()
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=库名;Data Source=127.0.0.1", "用户名", "密码"
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM 表名", conn, adOpenKeyset, adLockOptimistic
rst.MoveFirst
Do While Not rst.EOF
Debug.Print rst.Fields(0) & rst.Fields(1)
rst.MoveNext
Loop
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询