DataSet 反向更新数据库的数据增加

SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "data source=.;initial catalog=demo;user id=sa;password=sa";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from wz_ksdm";
            cmd.Connection = conn;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds, "wz_ksdm");
            DataSet ds1 = new DataSet();
            ds1.ReadXml(Application.StartupPath.ToString() + "http://www.cnblogs.com/../" + "WZKSDM.XML");
            ////ds.Tables["wz_da"].ReadXml();
            SqlCommand insertcmd = new SqlCommand();
            //insertcmd.CommandText = "insert into wz_bz(id,cyyfl,cyy) values(@id,@cyyfl,@cyy)";
            insertcmd.CommandText = "insert into wz_ksdm(ksdm,ksmc,srm1,srm2,srm3) values(@ksdm,@ksmc,@srm1,@srm2,@srm3)";

            insertcmd.Parameters.Add("@ksdm", SqlDbType.VarChar,10,"ksdm");
            insertcmd.Parameters.Add("@ksmc", SqlDbType.VarChar,30, "ksmc");
            insertcmd.Parameters.Add("@srm1", SqlDbType.VarChar,6, "srm1");
            insertcmd.Parameters.Add("@srm2", SqlDbType.VarChar,6, "srm2");
            insertcmd.Parameters.Add("@srm3", SqlDbType.VarChar,6,"srm3");
            da.InsertCommand = insertcmd;
            insertcmd.Connection = conn;
           MessageBox.Show(da.Update(ds1.Tables[0]).ToString()); 

你可能感兴趣的:(Data)