VB中如何用DataGridView显示Access数据库中的记录 5
我编写了下面的代码,就是不显示数据,请各位高手指点一下。DimstrConnAsString="provider=microsoft.jet.oledb.4.0;data...
我编写了下面的代码,就是不显示数据,请各位高手指点一下。
Dim strConn As String = "provider=microsoft.jet.oledb.4.0;data source=教材信息.mdb"
Dim objConn As New OleDbConnection(strConn)
Dim objAdap As New OleDbDataAdapter()
Dim objDset As New DataSet()
Dim strSql As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "" Then
strSql = "Select * From 教材1 where 教材名称= '" & TextBox1.Text & "'"
End If
objConn.Open()
objAdap.SelectCommand = New OleDbCommand(strSql, objConn)
objConn.Close()
objDset.Clear()
objAdap.Fill(objDset, "教材1")
DataGridView1.DataSource = objDset.Tables("教材1")
End Sub
我的数据库链接是没有问题的,因为浏览数据库的数据都可以,就是查询时,DataGridView里不显示数据,不知道哪里出了问题。 展开
Dim strConn As String = "provider=microsoft.jet.oledb.4.0;data source=教材信息.mdb"
Dim objConn As New OleDbConnection(strConn)
Dim objAdap As New OleDbDataAdapter()
Dim objDset As New DataSet()
Dim strSql As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "" Then
strSql = "Select * From 教材1 where 教材名称= '" & TextBox1.Text & "'"
End If
objConn.Open()
objAdap.SelectCommand = New OleDbCommand(strSql, objConn)
objConn.Close()
objDset.Clear()
objAdap.Fill(objDset, "教材1")
DataGridView1.DataSource = objDset.Tables("教材1")
End Sub
我的数据库链接是没有问题的,因为浏览数据库的数据都可以,就是查询时,DataGridView里不显示数据,不知道哪里出了问题。 展开
展开全部
Private Sub Form_Load()
Dim sql As String
Dim conn As New Connection
On Error GoTo loaderror '这是个判断错误的语句、如果执行错误gotoloaderror:下面的语句
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\db1.mdb"
sql = "select * from 供货商信息表"
rs_reader.CursorLocation = adUseClient
rs_reader.Open sql, conn, adOpenKeyset, adLockPessimistic
cmdupdate.Enabled = False
cmdcancel.Enabled = False
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_reader
Exit Sub
loaderror:
MsgBox Err.Description
End Sub
我做的仓库管理系统里的窗体加载datagrid信息
Dim sql As String
Dim conn As New Connection
On Error GoTo loaderror '这是个判断错误的语句、如果执行错误gotoloaderror:下面的语句
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\db1.mdb"
sql = "select * from 供货商信息表"
rs_reader.CursorLocation = adUseClient
rs_reader.Open sql, conn, adOpenKeyset, adLockPessimistic
cmdupdate.Enabled = False
cmdcancel.Enabled = False
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_reader
Exit Sub
loaderror:
MsgBox Err.Description
End Sub
我做的仓库管理系统里的窗体加载datagrid信息
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询