几个vb编程的有关问题纠结

几个vb编程的问题纠结
最近做成绩管理系统,做成绩导入模块时,需要将电脑中的excel表中的数据导入到sql数据库中,建立了一个按键,一个CommonDialog1控件,根据别人的程序修改如下(中间???那里不知道该修改成什-_-):

Private Sub command1_Click()
Dim strconn As String ' 定义连接字符串
' 初始化commandialog1 的属性
CommonDialog1.Filter = " 电子表格文件(.xls) |*.xls"
CommonDialog1.DialogTitle = " 请选择要导入的文件"
' 初始化记录集及连接
Set rstemp = CreateObject("ADODB.Recordset")
Set Conn = CreateObject("adodb.connection")
' 打开连接,并加参数
strconn = " Provider=SQLOLEDB.1;Persist Security Info=False;User ID =sa;password =sa;Initial Catalog =学籍分析管理系统;DataSource= KK-PC"
Conn.Open strconn
' 选取Excel 数据文件,文件路径及名称记录在Com
'monDialog1.FileName 中
CommonDialog1.ShowOpen
' 写SQL 语句,数据写入SQL Server 中
strsql = " select * into tablename from OpenRowSet( 'microsoft.jet.oledb.4.0','Excel 8.0;HDR =Yes;database =" & CommonDialog1.FileName & " ;','select * from [sheet1$] ')where 学号<>' ?????'"
rstemp.Open strsql, Conn, 1, 1
' 提示
MsgBox " 数据导入成功!", vbExclamation + vbOKOnly
' 关闭数据库连接及记录集,释放资源
Conn.Close
Set Conn = Nothing
rstemp.Close
Set rstemp = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
    '退出操作
    main.Enabled = True
    Unload Me
End Sub

运行时错误:连接服务器“(null)”的OLE DB访问接口''microsoft.jet.oledb.4.0''报错。提供程序未给出相关错误的任何信息

错误行:rstemp.Open strsql, Conn, 1, 1



求帮助下啊,各位
------解决方案--------------------
rstemp.Open strsql, Conn, 1, 1

改成

Conn.Execute strsql

试试。

联合使用 ADO 和 SQLOLEDB 来做 Excel 对 SQL server 的导入,是常规的做法。看看微软的例子:

Use ADO and SQLOLEDB
When you are connected to SQL Server in an ADO application by using Microsoft OLE DB for SQL 
Server (SQLOLEDB), you can use the same "distributed query" syntax from the Using Distributed 
Queries section to import Excel data into SQL Server.

The following Visual Basic 6.0 code sample requires that you add a project reference to ActiveX 
Data Objects (ADO). This code sample also demonstrates how to use OPENDATASOURCE and 
OPENROWSET over an SQLOLEDB connection. 

    Dim cn As ADODB.Connection
    Dim strSQL As String
    Dim lngRecsAff As Long
    Set cn = New ADODB.Connection
    cn.Open "Provider=SQLOLEDB;Data Source=<server>;" & _
        "Initial Catalog=<database>;User ID=<user>;Password=<password>"

    'Import by using OPENDATASOURCE.
    strSQL = "SELECT * INTO XLImport6 FROM " & _
        "OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', " & _
        "'Data Source=C:\test\xltest.xls;" & _
        "Extended Properties=Excel 8.0')...[Customers$]"
    Debug.Print strSQL
    cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
    Debug.Print "Records affected: " & lngRecsAff

    'Import by using OPENROWSET and object name.
    strSQL = "SELECT * INTO XLImport7 FROM " & _
        "OPENROWSET('Microsoft.Jet.OLEDB.4.0', " & _
        "'Excel 8.0;Database=C:\test\xltest.xls', " & _
        "[Customers$])"
    Debug.Print strSQL
    cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
    Debug.Print "Records affected: " & lngRecsAff

    'Import by using OPENROWSET and SELECT query.
    strSQL = "SELECT * INTO XLImport8 FROM " & _
        "OPENROWSET('Microsoft.Jet.OLEDB.4.0', " & _
        "'Excel 8.0;Database=C:\test\xltest.xls', " & _
        "'SELECT * FROM [Customers$]')"
    Debug.Print strSQL
    cn.Execute strSQL, lngRecsAff, adExecuteNoRecords