列名或所提供值的数目与表定义不匹配
时间:2011-12-22
来源:互联网
Private Sub Command1_Click()
CommonDialog1.FileName = ""
CommonDialog1.Filter = "(*.xls)"
CommonDialog1.FilterIndex = 2
CommonDialog1.DialogTitle = "Open File(*.xls)"
CommonDialog1.Action = 1
If CommonDialog1.FileName = "" Then
MsgBox "no file selectd", 37, "checking"
Else
Dim Cn As ADODB.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set Cn = New ADODB.Connection
Cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False; UID=sa; password =ww123456; Initial Catalog=student;Data Source=192.168.1.4"
strSQL = "INSERT INTO 学生信息 select " & _
"学号,姓名,性别,入学日期,系别,班级,宿舍号,是否在校生,学生状态,教育年制 FROM " & _
"OPENROWSET('Microsoft.Jet.OLEDB.4.0'," & _
"'Excel 8.0;Database=" & CommonDialog1.FileName & "',Sheet1$)"
Debug.Print strSQL
Cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
Debug.Print "Records affected: " & lngRecsAff
MsgBox "本次共导入" & lngRecsAff & "条记录!"
Cn.Close
Set Cn = Nothing
End If
End Sub
----------------------------
各位高手指导,这个程序运行提示“列名或所提供值的数目与表定义不匹配”。
CommonDialog1.FileName = ""
CommonDialog1.Filter = "(*.xls)"
CommonDialog1.FilterIndex = 2
CommonDialog1.DialogTitle = "Open File(*.xls)"
CommonDialog1.Action = 1
If CommonDialog1.FileName = "" Then
MsgBox "no file selectd", 37, "checking"
Else
Dim Cn As ADODB.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set Cn = New ADODB.Connection
Cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False; UID=sa; password =ww123456; Initial Catalog=student;Data Source=192.168.1.4"
strSQL = "INSERT INTO 学生信息 select " & _
"学号,姓名,性别,入学日期,系别,班级,宿舍号,是否在校生,学生状态,教育年制 FROM " & _
"OPENROWSET('Microsoft.Jet.OLEDB.4.0'," & _
"'Excel 8.0;Database=" & CommonDialog1.FileName & "',Sheet1$)"
Debug.Print strSQL
Cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
Debug.Print "Records affected: " & lngRecsAff
MsgBox "本次共导入" & lngRecsAff & "条记录!"
Cn.Close
Set Cn = Nothing
End If
End Sub
----------------------------
各位高手指导,这个程序运行提示“列名或所提供值的数目与表定义不匹配”。
作者: mayanhua110 发布时间: 2011-12-22
VB code
Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Set conn = New ADODB.Connection Set rs = New ADODB.Recordset conn.CursorLocation = adUseClient conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="EXCEL文件名";Extended Properties='Excel 8.0;HDR=Yes'" rs.Open "select * from [" & 工作表名 & "$]", conn, adOpenDynamic, adLockOptimistic Set MSHFlexGrid1.DataSource = rs
作者: Veron_04 发布时间: 2011-12-22
作者: Veron_04 发布时间: 2011-12-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28