本文介绍了关于数据库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
h0w在列表框或网格中显示数据库中表的内容......?
h0w to show the contents of table in database in listbox or in grid......?
推荐答案
Dim con As New ADODB.Connection
Dim Rs as new adodb.recordset
if con.state = 1 then con.close
''I am using Sql Server so i am using following string.. let me know what database you are using.
Con.Open _
"Provider = sqloledb;" & _
"Data Source=servername;" & _
"Initial Catalog=DatabaseName;" & _
"User ID=username;" & _
"Password=password;"
If RS.State = 1 Then RS.Close
RS.Open "select field1, field2, field3 from YourTable", con, adOpenKeyset, adLockOptimistic
If RS.RecordCount > 0 Then
Set DataGrid1.DataSource = RS
Else
msgbox "Record Not found", vbCritical, "My DataGrid"
end if
如果
Please let me know if you have more query.
这篇关于关于数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!