gridview绑定EXCEL数据源代码并生成SQL语句

string strCon1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source =D:\102盤點.xls;Extended Properties=Excel 8.0";
                        OleDbConnection myConn1 = new OleDbConnection(strCon1);
                        myConn1.Open();   //打开数据链接,得到一个数据集     
                        DataSet myDataSet1 = new DataSet();   //创建DataSet对象     
                        string StrSql1 = "select   *   from  [Sheet1$]";
                        OleDbDataAdapter myCommand1 = new OleDbDataAdapter(StrSql1, myConn1);
                        myCommand1.Fill(myDataSet1, "[Sheet1$]");
                        myCommand1.Dispose();
                        DataTable DT1 = myDataSet1.Tables["[Sheet1$]"];
                       

                        this.gvdata.DataSource = DT1;
                        gvdata.DataBind();
                        myConn1.Close();
                        myCommand1.Dispose();

                        this.Label2.Text = DT1.Rows.Count.ToString();

                        this.TextBox1.Visible = false;

 

 

 

 

 

//edit by sunblue 20080825
            ///導入料號資料
            //string sql = "insert into item_ex(item, Bclass, mclass, sclass, [desc], spec, ABCCode, unit, Warehouse";
            //sql += ")";
            //sql += "values(";
            //sql += "'" + gvdata.Rows[i].Cells[0].Text.Trim() + "', ";
            //sql += "'" + gvdata.Rows[i].Cells[1].Text.Trim() + "', ";
            //sql += "'" + gvdata.Rows[i].Cells[2].Text.Trim() + "', ";
            //sql += "'" + gvdata.Rows[i].Cells[3].Text.Trim() + "', ";
            //sql += "N'" + gvdata.Rows[i].Cells[4].Text.Trim() + "', ";
            //sql += "N'" + DFS.Web.PageBase.DecodeToText(gvdata.Rows[i].Cells[5].Text.Trim()).Replace("'", "''") + "', ";
            //sql += "'" + DFS.Web.PageBase.DecodeToText(gvdata.Rows[i].Cells[6].Text.Trim()).Replace("'", "''") + "', ";
            //sql += "'" + gvdata.Rows[i].Cells[7].Text.Trim() + "', ";
            //sql += "'" + gvdata.Rows[i].Cells[8].Text.Trim() + "' ";           
            //sql += ")";
           
            ///導入料號庫存值
            string sql = "insert into wms_cell_item(cellNO,item,itemQty,whNO";
            sql += ")";
            sql += "values(";
            sql += "'" + gvdata.Rows[i].Cells[0].Text.Trim() + "', ";
            sql += "'" + gvdata.Rows[i].Cells[1].Text.Trim() + "', ";
            sql += "'" + CoolFuncs.Str2Int(gvdata.Rows[i].Cells[2].Text.Trim()) + "', ";
            sql += "'" + gvdata.Rows[i].Cells[3].Text.Trim() + "' ";
            sql += ")";

            this.TextBox1.Text += sql + "\n";
            /*
            if (SC.MySqlBase.ExecuteSql(sql) > 0)
            {
                j++;
                this.TextBox1.Text += sql + "\n";
            }
            else
            {
                this.Label3.Text += sql + "<br />";
            }*/
            this.Label1.Text = j.ToString();


posted @ 2008-10-16 11:13  XGU_Winner  阅读(357)  评论(0编辑  收藏  举报