private void button2_Click_2(object sender, EventArgs e) { string connectionString = connStr.Text.Trim(); try { using (SAConnection conn = new SAConnection(connectionString)) //DataSet tester { DTAcctLog.Rows.Clear(); //doesn't affect the update. conn.Open(); //open connection from using block SADataAdapter da = new SADataAdapter("Select * from acctlog", conn); //create a new data adapter. I don't know what's special about this. SACommandBuilder cb = new SACommandBuilder(da); cb.ConflictOption = ConflictOption.OverwriteChanges; //cheaty bullshit for just overpowering the conflict changes negating the concurrency violation. da.Fill(DTAcctLog); //you have to fill it to update it. DTAcctLog.Rows[4]["repuid"] = 2000042; DTAcctLog.Rows[5]["repuid"] = 2000032; DTAcctLog.Rows[6]["repuid"] = 2000012; DTAcctLog.Rows[7]["repuid"] = 2000015; DTAcctLog.Rows[8]["repuid"] = 2000017; DTAcctLog.Rows[9]["repuid"] = 2000025; da.UpdateCommand = cb.GetUpdateCommand(); da.Update(DTAcctLog); DTAcctLog.AcceptChanges(); dataGridView1.DataSource = DTAcctLog; //da.Fill(DTAcctLog); } } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Error\n" + ex.Message + "\n\n" + ex.ToString()); } }
private void button1_Click_1(object sender, EventArgs e) { dataGridView1.DataSource = null; string connectionString = connStr.Text.Trim(); try { using (SAConnection conn = new SAConnection(connectionString)) //DataSet tester { conn.Open(); //open connection from using block SADataAdapter da = new SADataAdapter(); //create a new data adapter. I don't know what's special about this. da.SelectCommand = new SACommand("Select * from AcctLog", conn); dataGridView1.DataSource = DTAcctLog; SACommandBuilder cb = new SACommandBuilder(da); da.Fill(DTAcctLog); } } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Error\n" + ex.Message); } finally { dataGridView1.Refresh(); } }
public override void UpdateDataSet(string sqlQuery, ref DataSet dts) { SACommand cmd = null; try { if (_transaction != null && _currentState != ConnectionState.Open) { Open(); } if (dts.HasChanges()) { int i = 0; IList <string> queryPart = Regex.Split(sqlQuery, ";"); foreach (DataTable table in dts.Tables) { if (_transaction == null) { cmd = new SACommand(queryPart[i++], _connection); } else { cmd = new SACommand(queryPart[i++], _connection, _transaction); } SADataAdapter dta = new SADataAdapter(cmd); SACommandBuilder commandBuilder = new SACommandBuilder(dta); dta.Update(table); } } } catch (System.Exception e) { if (_transaction != null && _currentState != ConnectionState.Open) { Rollback(); } string msg = "DataAccessLayer Error: " + ShowMessage(e.Message); throw new System.Exception(msg); } finally { if (_transaction == null && _currentState == ConnectionState.Open) { Close(); } if (cmd != null) { cmd.Dispose(); } } }
private void button2_Click_1(object sender, EventArgs e) //send to DB { string connectionString = connStr.Text.Trim(); try { using (SAConnection conn = new SAConnection(connectionString)) //DataTable Tester { conn.Open(); SADataAdapter da = new SADataAdapter("select * from acctlog", conn); SACommandBuilder cb = new SACommandBuilder(da); da.Fill(DTAcctLog); da.Update(DTAcctLog); } } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Error\n" + ex.Message); } }
private void button2_Click_2(object sender, EventArgs e) { string connectionString = connStr.Text.Trim(); try { using (SAConnection conn = new SAConnection(connectionString)) //DataSet tester { DTAcctLog.Rows.Clear(); //doesn't affect the update. conn.Open(); //open connection from using block SADataAdapter da = new SADataAdapter("Select * from acctlog", conn); //create a new data adapter. I don't know what's special about this. SACommandBuilder cb = new SACommandBuilder(da); cb.ConflictOption = ConflictOption.OverwriteChanges; //cheaty bullshit for just overpowering the conflict changes negating the concurrency violation. da.Fill(DTAcctLog); //you have to fill it to update it. DTAcctLog.Rows[4]["repuid"] = 2000042; DTAcctLog.Rows[5]["repuid"] = 2000032; DTAcctLog.Rows[6]["repuid"] = 2000012; DTAcctLog.Rows[7]["repuid"] = 2000015; DTAcctLog.Rows[8]["repuid"] = 2000017; DTAcctLog.Rows[9]["repuid"] = 2000025; da.UpdateCommand = cb.GetUpdateCommand(); da.Update(DTAcctLog); DTAcctLog.AcceptChanges(); dataGridView1.DataSource = DTAcctLog; //da.Fill(DTAcctLog); } } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Error\n" + ex.Message + "\n\n" + ex.ToString() ); } }