private DataSet GetExcelDs()
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Excel 8.0";
            //链接Excel
            OleDbConnection cnnxls = new OleDbConnection(strConn);
            //读取Excel里面有 表Sheet1
            OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
            DataSet dsUpdate = new DataSet();
            //将Excel里面有表内容装载到内存表中!
            oda.Fill(dsUpdate, "newtable");
            return dsUpdate;
        }        private void btnUpdateMany_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet dsUpdate = this.GetExcelDs();
                da.UpdateCommand = new SqlCommand("sp_updateSngCode", conn);
                da.UpdateCommand.Parameters.Add("@loginName", SqlDbType.NVarChar, 50, "LoginName");
                da.UpdateCommand.Parameters.Add("@loginPass", SqlDbType.NVarChar, 50, "LoginPass");
                da.UpdateCommand.Parameters.Add("@trueName", SqlDbType.NVarChar, 50, "TrueName");
                da.UpdateCommand.Parameters.Add("@Ugroup", SqlDbType.NVarChar, 50, "Ugroup");
                da.UpdateCommand.Parameters.Add("@email", SqlDbType.NVarChar, 50, "Email");
                da.UpdateCommand.Parameters.Add("@wYPXJL", SqlDbType.NVarChar, 2000, "WYPXJL");
                da.UpdateCommand.Parameters.Add("@mobile", SqlDbType.NVarChar, 50, "Mobile");
                da.UpdateCommand.Parameters.Add("@tel", SqlDbType.Int, 50, "Tel");
                da.UpdateCommand.CommandType = CommandType.StoredProcedure;
                conn.Open();
                da.Update(dsUpdate.Tables["newtable"]);
                conn.Close();
                MessageBox.Show("修改成功!","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("修改失败!" + "\n" + ex.Message);
            }
        }可是这样修改的信息都没存到数据库里面去.
!!!!
有人可以帮我看一下吗???

解决方案 »

  1.   

    你的commend命令沒加到dataset中吧
      

  2.   

    没用过这种方法,但是怀疑问题原因是,你的 "@tel" 是个整数类型,而 oda.Fill(dsUpdate, "newtable");  时,因为数据是从Excel中得到的,所以其实这一列是个String类型。
    建议你 先不要用 da.Update(dsUpdate.Tables["newtable"]); 这个方法,而是循环把每一列的值得到,分别赋给每个Paramter对象,再执行看看结果如何。
      

  3.   

    跟踪一下报什么错?
    conn这个怎么没看到有定义啊?
      

  4.   

    da.Update(dsUpdate.Tables["newtable"])  跟踪了是  0
    dsUpdate.Tables["newtable"].Rows.Count  更总了是47 
    无语...