string conn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =D:/71.xls;Extended Properties=Excel 8.0";
            //"Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" + "Extended Properties=Excel 8.0;"
            OleDbConnection thisconnection = new OleDbConnection(conn);
            thisconnection.Open();
            string Sql = "select * from [Sheet1$]";
            OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, thisconnection);
            DataSet ds = new DataSet();
           
            mycommand.Fill(ds);
            int x = ds.Tables[0].Rows.Count;
            string xx = ds.Tables[0].Rows[1][0].ToString();
            SqlConnection thisconnection1 = new SqlConnection(ConfigurationManager.AppSettings["baihuajiang"]);
            thisconnection1.Open();
            int count = ds.Tables[0].Rows.Count;

            for (int j = 0; j < count; j++)
            {
                string id_1;
                id_1 = ds.Tables[0].Rows[j][0].ToString();
                string excelsql = "insert into yingyuan (name) values ('" + id_1 + "') ";
                SqlCommand mycommand1 = new SqlCommand(excelsql, thisconnection1);
                mycommand1.ExecuteNonQuery();
            }
             MessageBox.Show("更新成功");
            thisconnection1.Close();
            thisconnection.Close();


俺从网上找到,但是会有很多错误,俺们公司新来的程序员MM帮俺修改的,我是做什么的?我是混的,嘿嘿,我做技术支持,简称网管,现在学人家做程序,还很嫩,比东来顺的小羊肉还嫩。

posted on 2008-07-02 11:19  fuyan  阅读(297)  评论(0)    收藏  举报