用VB6.0编界面,访问access数据库,ado编程建立连接时无法向后台数据库插入多条记录
每次只能存一条记录,插入的第二条会把第一条的内容冲掉,请高手指教!必有重谢DimstrProviderAsStringDimstrDataSourceAsStringDi...
每次只能存一条记录,插入的第二条会把第一条的内容冲掉,请高手指教!必有重谢
Dim strProvider As StringDim strDataSource As String
Dim strDataBaseName As String
Dim connConnection As ADODB.Connection
Dim rsRecordSet As ADODB.Recordset
Private Sub Command1_Click()rsRecordSet.Update
rsRecordSet.MoveNext
End Sub
Private Sub Form_Load()strProvider = "Provider = Microsoft.Jet.OLEDB.4.0;"
strDataSource = App.Path
strDataBaseName = "\db2.mdb"
strDataSource = "Data Source=" & strDataSource & strDataBaseName
strConnect = strProvider & strDataSource
'设置connection对象-connConnection的属性Set connConnection = New ADODB.Connection
connConnection.CursorLocation = adUseClient
connConnection.Open strConnect 'strConnect是数据库连接字符串,定向到db2.mdb
'设置recordset对象-rsRecordSet的属性Set rsRecordSet = New ADODB.Recordset
rsRecordSet.CursorType = adOpenStatic
rsRecordSet.CursorLocation = adUseClient
rsRecordSet.LockType = adLockPessimistic
rsRecordSet.Source = "select * from 学生表"
rsRecordSet.ActiveConnection = connConnection
rsRecordSet.Open
'如果没有记录,则插入新记录
If rsRecordSet.RecordCount = 0 Then
rsRecordSet.AddNew
' rsRecordSet.Fields("处方号").Value = Text1.Text
Set Text1.DataSource = rsRecordSet
Text1.DataField = "学号"
Set Text2.DataSource = rsRecordSet
Text2.DataField = "姓名"
Else
Set Text1.DataSource = rsRecordSet
Text1.DataField = "学号"
Set Text2.DataSource = rsRecordSet
Text2.DataField = "姓名"
End IfEnd Sub 展开
Dim strProvider As StringDim strDataSource As String
Dim strDataBaseName As String
Dim connConnection As ADODB.Connection
Dim rsRecordSet As ADODB.Recordset
Private Sub Command1_Click()rsRecordSet.Update
rsRecordSet.MoveNext
End Sub
Private Sub Form_Load()strProvider = "Provider = Microsoft.Jet.OLEDB.4.0;"
strDataSource = App.Path
strDataBaseName = "\db2.mdb"
strDataSource = "Data Source=" & strDataSource & strDataBaseName
strConnect = strProvider & strDataSource
'设置connection对象-connConnection的属性Set connConnection = New ADODB.Connection
connConnection.CursorLocation = adUseClient
connConnection.Open strConnect 'strConnect是数据库连接字符串,定向到db2.mdb
'设置recordset对象-rsRecordSet的属性Set rsRecordSet = New ADODB.Recordset
rsRecordSet.CursorType = adOpenStatic
rsRecordSet.CursorLocation = adUseClient
rsRecordSet.LockType = adLockPessimistic
rsRecordSet.Source = "select * from 学生表"
rsRecordSet.ActiveConnection = connConnection
rsRecordSet.Open
'如果没有记录,则插入新记录
If rsRecordSet.RecordCount = 0 Then
rsRecordSet.AddNew
' rsRecordSet.Fields("处方号").Value = Text1.Text
Set Text1.DataSource = rsRecordSet
Text1.DataField = "学号"
Set Text2.DataSource = rsRecordSet
Text2.DataField = "姓名"
Else
Set Text1.DataSource = rsRecordSet
Text1.DataField = "学号"
Set Text2.DataSource = rsRecordSet
Text2.DataField = "姓名"
End IfEnd Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询