太阁立志传5 称号:请教一个VB跟数据库连接的问题

来源:百度文库 编辑:高考问答 时间:2024/04/28 21:41:13
就是在一个添加界面,放了一个ComboBox控件,里面有5个选项,这5个选项分别对应数据库里的5个表,如何将题目添加到指定的表中.哪位朋友帮忙写段代码上来看看.谢谢!急!!!
数据库是用的Access2000

Dim cn as New ADODB.Connection
Dim rst as New ADODB.Recordset
Dim strTable as String '表名称

strTable =Combo1.text

With objConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & 数据库名称(全路径)
.Open
End With

With rst
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open strTable ,cn, , , adCmdTable
End with

rst.AddNew
rst!字段名=题目
rst.Update

rst.close
Set rst=Nothing
Set cn=Nothing