谁有例子啊?
ADO.NET
C#.NET的啊.

解决方案 »

  1.   

    调用SQL SERVER 的DTS试试.
      

  2.   

    Dim cn As ADODB.Connection
        Dim strSQL As String
        Dim lngRecsAff As Long
        Set cn = New ADODB.Connection
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\test\xltestt.xls;" & _
            "Extended Properties=Excel 8.0"    'Import by using Jet Provider.
        strSQL = "SELECT * INTO [odbc;Driver={SQL Server};" & _
            "Server=<server>;Database=<database>;" & _
            "UID=<user>;PWD=<password>].XLImport9 " & _
            "FROM [Customers$]"
        Debug.Print strSQL
        cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
        Debug.Print "Records affected: " & lngRecsAff    cn.Close
        Set cn = Nothing
    这个VB怎么用C#来写啊?
      

  3.   

    或者写一个excel导入ms sql server的存储过程,然后在c#里调。
      

  4.   

    private void ImportExcelData()
    {
    this.SetStyle("Table");
    string file="";
    openFileDialog1.Filter = "Excel数据文件|*.xls";
                openFileDialog1.RestoreDirectory = true;
    if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
    {
    file=this.openFileDialog1.FileName;
    //
    string conStr=@" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = "+file+";Password=;User ID=Admin;Extended Properties=Excel 8.0" ;  string cmdText="select * from [Sheet1$]"; OleDbDataAdapter a=new OleDbDataAdapter(cmdText,conStr); DataSet ds=new DataSet(); a.Fill(ds);
    this.data=ds.Tables[0];
    //string cols="学号,姓名,班级名称,院系名称";
    this.dataGrid1.DataSource=this.data;
    //
    this.label1.Visible=true;
    this.label2.Text="共有"+this.data.Rows.Count.ToString()+"条记录;";
    }
      

  5.   

    关键在这里:
    string conStr=@" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = "+file+";Password=;User ID=Admin;Extended Properties=Excel 8.0" ;  string cmdText="select * from [Sheet1$]";
      

  6.   

    public static DataSet CreateDataSetFromExcel(string pcExcelFilePath)
    {
    DataSet loRetVal = null; if (pcExcelFilePath.Trim().Length>0)
    {
    try
    {
    loRetVal = new DataSet();
    string strConn;
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source="+pcExcelFilePath+";"+
    "Extended Properties=Excel 8.0;";
    OleDbConnection conn = new OleDbConnection(strConn);
    OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [sheet1$]", strConn);
    myCommand.Fill(loRetVal);
    }
    catch (Exception loErr)
    {
    AppEnv.InfoBox(loErr.Message);
    }
    } return loRetVal;
    }