ASP.NET: excel加两列导入到sqlserver

     OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data  Source="+filename+";User ID=Admin;Password=;Extended properties=Excel 8.0");
    conn.Open();
     DataTable dt=conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null,null,null,"TABLE"});
     string eName="["+dt.Rows[0]["TABLE_NAME"].ToString ().Trim()+"]";

     OleDbCommand cmd = new OleDbCommand("insert into [ODBC;Driver=SQL Server;UID=sa;PWD=;Server=ck;DataBase=tb2;].gz select *,'"+DL_Y.SelectedItem.Text+"' as [year],'"+DL_M.SelectedItem.Text+"' as [month] from "+eName,conn);

你可能感兴趣的:(sqlserver)