发现只要EXCEL列中的内容大于256的就不能导如sql server中,后来在网上查到说,不能导如大于255的数据.请问有什么解决办法吗?
 dim cn As New ADODB.Connection  'connection excel
dim  con As New ADODB.Connection 'connection sql server
 con.ConnectionString = "Provider=SQLOLEDB;Data Source=Testsqls01;Initial Catalog=EIR;User Id=EIRadmin;Password=eiradmin;" 
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source='" & txt & "';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"cn.Open
con.Open Set xlApp = CreateObject("Excel.Application")
    Set xlbook = xlApp.Workbooks.Open("c:\a.xls")
    For i = 1 To xlbook.Sheets.Count
              If i = xlbook.Sheets.Count Then
    rs.Open "select * From [" & xlbook.Sheets(i).Name & "$]", cn, adOpenDynamic, adLockPessimistic
               While Not rs.EOF
 
                      
                    If rs(0) <> "" And rs(1) <> "" Then
                     If rs(0) = "OFU-EN0013" Then
                           MsgBox (rs(1))
                      End If
                        tmpLocation = "Insert Into RULocation(RULabel,OPZoneGroupName,[Year],Week,LastUpdateDate,LastUpdateBy)Values('" & rs(0) & "','" & rs(1) & "','" & txtYear.Text & "','" & txtWeek.Text & "','" & Now() & "','david')" ','" & Now() & "'
                        con.Execute tmpLocation
                    End If
                rs.MoveNext
              Wend
              rs.Close
              Set rs = Nothing 
 xlbook.Close False
          xlApp.Quit
          Set xlbook = Nothing
          Set xlApp = Nothing
          cn.Close
          con.Close

解决方案 »

  1.   

    可以用这种形式str="select * from sql数据表"
    rs.open str ,conn,3,1rs.addnewrs("")=excel'execel中对应的数据
    .....
    .....
    rs.update
      

  2.   

    字符长度在SQL几乎不是问题。
      

  3.   

    “EXCEL列中的内容大于256”导入SQL Server 没任何问题啊
      

  4.   

    当excel某个单元格的值大于256时,不可能,字符长度大于256时,很有可能。那不是SQL Server的问题,估计是odbc访问excel时的限制原因。
      

  5.   

    我发现是recordset的问题,当我用rs.open 打开excel之后,假设excel某个字段的内容大于256,rs("filedname")就会切掉多余的部分,有什么方法解决
      

  6.   

    能不能先设置好recordset的字段的长度. 因为excel的字段是固定的.
           就如下所示,
           rs.Fields.Append "Rulable", adVarChar, 2000
           rs.Fields.Append "RuGroup", adVarChar, 2000
                   
                  
                 rs.Open "select * From [" & xlbook.Sheets(i).Name & "$]", cn, adOpenDynamic, adLockPessimistic
    但我发现好象不可以.