vb.net2010+access 如何修改数据库信息
如何点击Button1,使数据库中的tb.Rows(0).Item(0),改成常量“red”,数据库如下:cc_idcc_ztcc1bluecc2red这是我的代码,请教...
如何点击Button1,使数据库中的tb.Rows(0).Item(0),改成常量“red”,数据库如下:
cc_id cc_zt
cc1 blue
cc2 red
这是我的代码,请教Button1_Click代码如何写???
Public Class Form1
Public cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\dxz.mdb") '定义连接,dxz.mdb和程序文件在同一目录
Public tb As DataTable = DataRead("select cc_zt from cc ")
Public aa As String
Public Function DataRead(ByVal str As String) As DataTable '读数据函数
Try
Dim tb_temp As New DataTable
Dim ap As New OleDb.OleDbDataAdapter(str, cn)
ap.Fill(tb_temp)
Return tb_temp
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
End Try
End Function
Private Sub Form1_BindingContextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.BindingContextChanged
If tb Is Nothing Then Exit Sub '如果读取错误退出
aa = tb.Rows(0).Item(0)
Label1.Text = aa
End Sub
End Class 展开
cc_id cc_zt
cc1 blue
cc2 red
这是我的代码,请教Button1_Click代码如何写???
Public Class Form1
Public cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\dxz.mdb") '定义连接,dxz.mdb和程序文件在同一目录
Public tb As DataTable = DataRead("select cc_zt from cc ")
Public aa As String
Public Function DataRead(ByVal str As String) As DataTable '读数据函数
Try
Dim tb_temp As New DataTable
Dim ap As New OleDb.OleDbDataAdapter(str, cn)
ap.Fill(tb_temp)
Return tb_temp
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
End Try
End Function
Private Sub Form1_BindingContextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.BindingContextChanged
If tb Is Nothing Then Exit Sub '如果读取错误退出
aa = tb.Rows(0).Item(0)
Label1.Text = aa
End Sub
End Class 展开
1个回答
展开全部
Dim cm As New OleDb.OleDbCommand
cn.Open()
If cn.State = ConnectionState.Open Then
cm.Connection = cn
cm.CommandText ="update tb set cc_zt='red' where cc_id='cc1'"
cm.ExecuteNonQuery()
end if
cn.Open()
If cn.State = ConnectionState.Open Then
cm.Connection = cn
cm.CommandText ="update tb set cc_zt='red' where cc_id='cc1'"
cm.ExecuteNonQuery()
end if
追问
不行呀,报错,{"Microsoft Jet 数据库引擎找不到输入表或查询 'tb'。 确定它是否存在,以及它的名称的拼写是否正确。"},如果改成“update cc set cc_zt='red' where cc_id='cc1'”,修改不了数据库呀
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询