我使用Jet.OLEDB.4.0与excel创建连接,通过bindingSource绑定,如何实现对excel表的增删改查?本人新手,高手请教(最好有代码)

解决方案 »

  1.   

    建议bindingSource结合gridview一起使用~!
    DataTable dt = (DataTable)(bindingSource1.DataSource);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string sendGoodsDate = "";
                    if (dt.Rows[i]["SendGoodsDate"] is DateTime)
                    {
                        sendGoodsDate = DateTimeTool.ToStringMidLine(dt.Rows[i]["SendGoodsDate"]);
                    }
                    string sql = "insert into [发货清单$](产品名称,产品型号,数量,[单价(元)],[总价(元)],发货日期,交货方式,到货地点,联系方式,供应商) values("
                        + "'" + dt.Rows[i]["GoodsName"].ToString() + "',"
                        + "'" + dt.Rows[i]["GoodsModel"].ToString() + "',"
                        + "'" + dt.Rows[i]["GoodsCount"].ToString() + "',"
                        + "'" + dt.Rows[i]["UnitPrice"].ToString() + "',"
                        + "'" + dt.Rows[i]["TotalPrice"].ToString() + "',"
                        + "'" + sendGoodsDate + "',"
                        + "'" + dt.Rows[i]["RecvGoodsPlace"].ToString() + "',"
                        + "'" + dt.Rows[i]["DhDesc"].ToString() + "',"
                        + "'" + dt.Rows[i]["Contact"].ToString() + "',"
                        + "'" + dt.Rows[i]["Supplier"].ToString() + "')";
                    DBOperate.ExecuteNonQuery(sql, DBOperate.DriverType.OleDb, DBOperate.GetConnStringExcel(_fileName));
                }
                System.Diagnostics.Process.Start(_fileName);
    这是我以前写的一个列子!