急啊!哪位大神能给个vb.net2008连接access数据库,写入、读取、显示的程序和代码啊,仅有的财富全部奉上
展开全部
Private strConnect As String = "driver={microsoft access driver (*.mdb)};uid=admin;pwd=;dbq=" & Application.StartupPath & "\DtBase.mdb"
Dim cn As New OdbcConnection(strConnect)
Dim da As New OdbcDataAdapter("SELECT * FROM 表名 WHERE 数值 > " & txtbox1.Text , cn)
Dim ds As New DataSet
da.Fill(ds, "表名")
Dim dtTable As New DataTable
dtTable = ds.Tables("表名") '获得检索出的数据赋值给dtTable表
DataGridView1.DataSource = dtTable ‘还可以为DataGridView添加列名和数据源
Dim cmdBuilder As New OdbcCommandBuilder(da)
da.InsertCommand = cmdBuilder.GetInsertCommand
Try
With ds.Tables("Units")
Dim dr As DataRow = .NewRow
dr("字段名") = "值"
.Rows.Add(dr)
End With
da.Update(ds, "表名")
Catch ex As Exception
throw ex
Finally
cn.Close()
cn.Dispose()
Dim cn As New OdbcConnection(strConnect)
Dim da As New OdbcDataAdapter("SELECT * FROM 表名 WHERE 数值 > " & txtbox1.Text , cn)
Dim ds As New DataSet
da.Fill(ds, "表名")
Dim dtTable As New DataTable
dtTable = ds.Tables("表名") '获得检索出的数据赋值给dtTable表
DataGridView1.DataSource = dtTable ‘还可以为DataGridView添加列名和数据源
Dim cmdBuilder As New OdbcCommandBuilder(da)
da.InsertCommand = cmdBuilder.GetInsertCommand
Try
With ds.Tables("Units")
Dim dr As DataRow = .NewRow
dr("字段名") = "值"
.Rows.Add(dr)
End With
da.Update(ds, "表名")
Catch ex As Exception
throw ex
Finally
cn.Close()
cn.Dispose()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询