EDN Admin
Well-known member
I have a windows application in which i have a textbox, datagridview and a button i am connecting to oracle database and passing SQL queries from my textbox on button click event. These SQL queries can be select,insert,update,delete or any thing its working
fine but all insert,update, delete or DML commands are getting auto committed. When i pass rollback from my textbox the data is not getting rolled back.Please help me how i can do this with transactions.I have tried some code
private void button2_Click(object sender, EventArgs e)<br/>
{<br/>
con.Open();<br/>
string querytext = textBox1.Text.ToString();<br/>
<br/>
OracleTransaction txn = con.BeginTransaction();<br/>
OracleCommand cmd = new OracleCommand(querytext, con);<br/>
cmd.Transaction = txn;<br/>
try<br/>
{<br/>
<br/>
cmd.CommandText = querytext;<br/>
cmd.ExecuteNonQuery();<br/>
<br/>
<br/>
cmd.CommandText = "select * from t1";<br/>
cmd.ExecuteScalar();<br/>
OracleDataAdapter da = new OracleDataAdapter(cmd);<br/>
DataTable dt = new DataTable();<br/>
da.Fill(dt);<br/>
dataGridView1.DataSource = dt;<br/>
//con.Close();<br/>
}<br/>
<br/>
catch (Exception ex)<br/>
{<br/>
MessageBox.Show(ex.Message);<br/>
}<br/>
<br/>
con.Close();<br/>
}
but in the above code until unless i write select command its not getting rolled back please help me in this regard
<
sonali
View the full article
fine but all insert,update, delete or DML commands are getting auto committed. When i pass rollback from my textbox the data is not getting rolled back.Please help me how i can do this with transactions.I have tried some code
private void button2_Click(object sender, EventArgs e)<br/>
{<br/>
con.Open();<br/>
string querytext = textBox1.Text.ToString();<br/>
<br/>
OracleTransaction txn = con.BeginTransaction();<br/>
OracleCommand cmd = new OracleCommand(querytext, con);<br/>
cmd.Transaction = txn;<br/>
try<br/>
{<br/>
<br/>
cmd.CommandText = querytext;<br/>
cmd.ExecuteNonQuery();<br/>
<br/>
<br/>
cmd.CommandText = "select * from t1";<br/>
cmd.ExecuteScalar();<br/>
OracleDataAdapter da = new OracleDataAdapter(cmd);<br/>
DataTable dt = new DataTable();<br/>
da.Fill(dt);<br/>
dataGridView1.DataSource = dt;<br/>
//con.Close();<br/>
}<br/>
<br/>
catch (Exception ex)<br/>
{<br/>
MessageBox.Show(ex.Message);<br/>
}<br/>
<br/>
con.Close();<br/>
}
but in the above code until unless i write select command its not getting rolled back please help me in this regard
<
sonali
View the full article