列名或所提供值的数目与表定义不匹配
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
----------------------------
各位高手指导,这个程序运行提示“列名或所提供值的数目与表定义不匹配”。
http://zhidao.baidu.com/question/200819684.html 这.......我的意思是我这段代码怎么改就可以了?
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
补充:VB , 网络编程