string tbl = "ConfArticle"; string sqlStr = string.Concat("SELECT * FROM ", tbl); try { OleDbConnection cnn = new OleDbConnection(cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; if (textBox2.Text.Trim() != id4edit.Trim()) while (drr.Read()) { if (drr["P_ID"].ToString().Trim() == textBox2.Text.Trim()) { found = true; break; } } if (!found) { dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; ++i) { dr = dt.Rows[i]; if (dr["P_ID"].ToString().Trim() == id4edit.Trim()) { dr.BeginEdit(); dr["P_ID"] = textBox2.Text.Trim(); dr["Art_Title"] = textBox6.Text.Trim(); dr["Reg_No"] = textBox4.Text.Trim(); dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); MessageBox.Show("Updated!!"); } else { ds.RejectChanges(); MessageBox.Show("Rejected"); } break; } } } else MessageBox.Show("Duplicate Error"); drr.Close(); cnn.Close(); dt.Dispose(); ds.Dispose(); drr.Dispose(); cmd.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt = null; ds = null; drr = null; cmd = null; ocb = null; oda = null; cnn = null; } catch (Exception ex) { MessageBox.Show("Error:\n\t" + ex.Message); } finally { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)