使用VB 将text控件中的值如何写到Access数据库中呢
一个form1和一个text1还有一个command1代码如下PrivateSubCommand1_Click()DimcnAsNewADODB.ConnectionDi...
一个form1 和一个text1 还有一个command1 代码如下
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
db_path = App.Path
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db_path & "\VB.mdb"
If rs.State <> adStateClosed Then rs.Close
rs.CursorLocation = adUseClient
sql = "Select * From Info where Mark = 'hp'"
'rs.Open "Info", cn, adOpenKeyset, adLockOptimistic
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
''Debug.Print rs.RecordCount
‘====================
现在是可以连接到Access上,也可以从中读出想要的值,但是我想写值进去,如何写呀请各位高手指教!
数据库名VB.mdb 表名Info 字段随意怎么样都行
‘====================
cn.Close
Set cn = Nothing
End Sub 展开
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
db_path = App.Path
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db_path & "\VB.mdb"
If rs.State <> adStateClosed Then rs.Close
rs.CursorLocation = adUseClient
sql = "Select * From Info where Mark = 'hp'"
'rs.Open "Info", cn, adOpenKeyset, adLockOptimistic
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
''Debug.Print rs.RecordCount
‘====================
现在是可以连接到Access上,也可以从中读出想要的值,但是我想写值进去,如何写呀请各位高手指教!
数据库名VB.mdb 表名Info 字段随意怎么样都行
‘====================
cn.Close
Set cn = Nothing
End Sub 展开
1个回答
展开全部
想写值进去修改sql = "Select * From Info where Mark = 'hp'"就可以了,例如:
插入一行:
sql="INSERT INTO infor " _
& "(FirstName,LastName, Title) VALUES " _
& "('Harry', 'Washington', 'Trainee');"
修改值:
sql="UPDATE infor " _
& "SET ReportsTo = 5 " _
& "WHERE ReportsTo = 2;"
插入一行:
sql="INSERT INTO infor " _
& "(FirstName,LastName, Title) VALUES " _
& "('Harry', 'Washington', 'Trainee');"
修改值:
sql="UPDATE infor " _
& "SET ReportsTo = 5 " _
& "WHERE ReportsTo = 2;"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询