Adodc1.Recordset.addnew的声明和使用问题 50
PrivateSubCommand2_Click()DimrecnumAsLong'记录数DimbooknameAsStringDimauthorAsStringDimi...
Private Sub Command2_Click()
Dim recnum As Long '记录数
Dim bookname As String
Dim author As String
Dim isbn As String
Dim publisher As String
Dim publisher_date As String
Dim price As String
Dim class_name As String
Dim book_num As String
Dim provider As String
Dim ex_rows As Long
Dim ex_cols As Long
'读取EXCEL文件中的数据,及行数,列数
Set ex = CreateObject("Excel.Application")
Set exwbook = ex.Workbooks.Open(Text1.Text)
Set Sheet = exwbook.Worksheets(1)
Set sv_rng = Sheet.UsedRange
ex_rows = sv_rng.Rows.Count '从EXCEL表中数据行数
ex_cols = sv_rng.Columns.Count 'EXCEL表中数据列数
recnum = ex_rows - 1
For i = 2 To ex_rows
student_id = Sheet.Cells(i, 1)
student_name = Sheet.Cells(i, 2)
student_sex = Sheet.Cells(i, 3)
born_date = Sheet.Cells(i, 4)
class_no = Sheet.Cells(i, 5)
tel_number = Sheet.Cells(i, 6)
ru_date = Sheet.Cells(i, 7)
Address = Sheet.Cells(i, 8)
Comment = Sheet.Cells(i, 9)
adode.Recordset.AddNew
adode.Recordset("student_id") = student_id
adode.Recordset("student_name") = student_name
adode.Recordset("student_sex") = student_sex
adode.Recordset("born_date") = born_date
adode.Recordset("class_no") = class_no
adode.Recordset("tel_number") = tel_number
adode.Recordset("ru_date") = ru_date
adode.Recordset("Address") = Address
adode.Recordset("Comment") = Comment
adode.Recordset.Update
Me.Caption = "正在进行数据转入,记录号为:" & Str(i - 1)
Next i 'EXCEE一行一行读取
exwbook.Close
MsgBox "数据处理完成!共转入记录数为:" & recnum
End Sub
这是想把EXCEL表中的文件直接导入数据库student中。代码是直接复制书本上的,运行的时候出错提示的是adodc1.recordset.addnew这“要求对象”。请问这个应该怎么声明的;我是菜鸟。。临时做一个简单系统学的VB,麻烦大大讲解得细致点。
贴上VB和SQL的连接函数(不知道有没关系):
Public Function ConnectString() As String
ConnectString = "Provider=SQLOLEDB.1;Password=;User ID=sa;Initial Catalog=student; Data Source =XDN-F217A606117"
End Function
原本是adodc1的字符写成了adode...不好意思 展开
Dim recnum As Long '记录数
Dim bookname As String
Dim author As String
Dim isbn As String
Dim publisher As String
Dim publisher_date As String
Dim price As String
Dim class_name As String
Dim book_num As String
Dim provider As String
Dim ex_rows As Long
Dim ex_cols As Long
'读取EXCEL文件中的数据,及行数,列数
Set ex = CreateObject("Excel.Application")
Set exwbook = ex.Workbooks.Open(Text1.Text)
Set Sheet = exwbook.Worksheets(1)
Set sv_rng = Sheet.UsedRange
ex_rows = sv_rng.Rows.Count '从EXCEL表中数据行数
ex_cols = sv_rng.Columns.Count 'EXCEL表中数据列数
recnum = ex_rows - 1
For i = 2 To ex_rows
student_id = Sheet.Cells(i, 1)
student_name = Sheet.Cells(i, 2)
student_sex = Sheet.Cells(i, 3)
born_date = Sheet.Cells(i, 4)
class_no = Sheet.Cells(i, 5)
tel_number = Sheet.Cells(i, 6)
ru_date = Sheet.Cells(i, 7)
Address = Sheet.Cells(i, 8)
Comment = Sheet.Cells(i, 9)
adode.Recordset.AddNew
adode.Recordset("student_id") = student_id
adode.Recordset("student_name") = student_name
adode.Recordset("student_sex") = student_sex
adode.Recordset("born_date") = born_date
adode.Recordset("class_no") = class_no
adode.Recordset("tel_number") = tel_number
adode.Recordset("ru_date") = ru_date
adode.Recordset("Address") = Address
adode.Recordset("Comment") = Comment
adode.Recordset.Update
Me.Caption = "正在进行数据转入,记录号为:" & Str(i - 1)
Next i 'EXCEE一行一行读取
exwbook.Close
MsgBox "数据处理完成!共转入记录数为:" & recnum
End Sub
这是想把EXCEL表中的文件直接导入数据库student中。代码是直接复制书本上的,运行的时候出错提示的是adodc1.recordset.addnew这“要求对象”。请问这个应该怎么声明的;我是菜鸟。。临时做一个简单系统学的VB,麻烦大大讲解得细致点。
贴上VB和SQL的连接函数(不知道有没关系):
Public Function ConnectString() As String
ConnectString = "Provider=SQLOLEDB.1;Password=;User ID=sa;Initial Catalog=student; Data Source =XDN-F217A606117"
End Function
原本是adodc1的字符写成了adode...不好意思 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询