private Boolean dbUpdate() { string strSql = "select ProductsSpecID,ProductsSpec,ProductsSpecUnit,ProductsID from tbl_product_detail_master"; System.Data.DataTable dtUpdate = new System.Data.DataTable(); dtUpdate = this.dbconn(strSql); dtUpdate.Rows.Clear();
System.Data.DataTable dtShow = new System.Data.DataTable(); //dtShow = (DataTable)this.bindSource.DataSource; dtShow = (System.Data.DataTable)this.dgselect.DataSource;
int p1 = dtShow.Rows.Count; // try // {
for (int i = 0; i < dtShow.Rows.Count; i++) { DataRowState rowState=new DataRowState(); rowState=dtShow.Rows[i].RowState; if (rowState==DataRowState.Added || rowState==DataRowState.Detached || rowState==DataRowState.Modified) {
if (this.dgselect["Del", i].Value.ToString() == "1") { dtShow.Rows[i].Delete(); } } } for (int i = 0; i < dtShow.Rows.Count; i++) { dtUpdate.ImportRow(dtShow.Rows[i]); } int num = dtUpdate.Rows.Count; try { this.conn.Open(); trans = this.conn.BeginTransaction();
MySqlCommandBuilder CommandBuiler; CommandBuiler = new MySqlCommandBuilder(this.adapter);
this.adapter.Update(dtUpdate); trans.Commit(); this.conn.Close();
} catch ( Exception ex) { MessageBox.Show(ex.Message.ToString()); trans.Rollback(); return false; }
dtUpdate.AcceptChanges(); return true;
}
|
请发表评论