insert into opportunity select * from openrowset('MicroSoft.Jet.OleDB.4.0','Excel 5.0;HDR=no;Database=" + Server.MapPath(newfile) + "\\" + newfilename + "',opportunity$)
opportunity 表里有4个字段(id/递增 names notes contents),excel表里opportunity有2个字段 notes和contents  
(names 的插入值为“会员”字符串    id为递增字段)
请问该如何修改这个插入程序啊

解决方案 »

  1.   

    tryinsert into opportunity(names, notes, contents) 
    select '会员', notes, contents from openrowset('MicroSoft.Jet.OleDB.4.0','Excel 5.0;HDR=no;Database=" + Server.MapPath(newfile) + "\\" + newfilename + "',opportunity$)
      

  2.   

    using System.Data.OleDb;string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath ( "data.xls" ) + ";Extended Properties=Excel 8.0";
    OleDbConnection conn = new OleDbConnection(connstr);
    string sql = "SELECT * FROM [Sheet1$]";
      

  3.   

    odbc
                string str = @"Driver=Microsoft Excel Driver (*.xls);Dbq=c:\abc.xls;";
                con = new OdbcConnection(str);
                da = new OdbcDataAdapter("select * from [sheet1$]", con);
                dt = new DataTable();
                da.Fill(dt);
                dataGrid1.DataSource = dt;
    oledb            string str = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\abc.xls;Extended Properties=Excel 8.0;";
                con = new OleDbConnection(str);
                da = new OleDbDataAdapter("select * from [sheet1$]", con);
                dt = new DataTable();
                da.Fill(dt);
                dataGrid1.DataSource = dt;