W
WebDevHokie
I have a very simple example that I am trying to get the update and delete
(through DataAdapter) working. I have the insert working just fine, but the
update/delete do not work. This is a win app if that matters. I get a
concurrency update (or delete) error saying that no rows are updated (or
deleted). Anyone have any idea what I could be doing wrong????
Thanks in advance!!
WebDevHokie
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button2;
private System.Data.DataSet _dataSet = new DataSet();
// puts the data in the datagrid
private void button1_Click(object sender, System.EventArgs e)
{
this._dataSet.Clear();
DDTek.Oracle.OracleConnection o_Connection = new
OracleConnection("Server Name=RPLANS;User ID=rplans_dev;Password=g00dwill");
o_Connection.Open();
DDTek.Oracle.OracleCommand o_Command = new OracleCommand("Select *
from MIKEW_QUERY_TEST", o_Connection);
DDTek.Oracle.OracleDataAdapter o_DataAdapter = new
OracleDataAdapter(o_Command);
o_DataAdapter.Fill(_dataSet);
dataGrid1.SetDataBinding(this._dataSet,
this._dataSet.Tables[0].TableName);
o_Connection.Close();
o_Connection.Dispose();
o_DataAdapter.Dispose();
o_Command.Dispose();
}
// performs the modification
private void button2_Click(object sender, System.EventArgs e)
{
DDTek.Oracle.OracleConnection o_Connection = new
OracleConnection("Server Name=Test_DB;User ID=Test_User;Password=Test");
DDTek.Oracle.OracleParameter o_Parameter;
o_Connection.Open();
// insert command
DDTek.Oracle.OracleCommand o_Command1 = new OracleCommand("Insert
into QUERY_TEST (ID, NAME, PHONE) values (?,?,?)", o_Connection);
o_Command1.Parameters.Add(new OracleParameter("ID",
OracleDbType.Number, 0, "ID"));
o_Command1.Parameters.Add(new OracleParameter("NAME",
OracleDbType.VarChar, 25, "NAME"));
o_Command1.Parameters.Add(new OracleParameter("PHONE",
OracleDbType.Number, 0, "PHONE"));
// delete command
DDTek.Oracle.OracleCommand o_Command2 = new OracleCommand("DELETE
from MIKEW_QUERY_TEST where ID = ?", o_Connection);
OracleParameterCollection o_ParameterCollection =
o_Command2.Parameters;
o_Parameter = new OracleParameter("ID", OracleDbType.Number, 0,
"ID");
o_Parameter.SourceVersion = DataRowVersion.Original;
o_Command2.Parameters.Add(o_Parameter);
// update command
DDTek.Oracle.OracleCommand o_Command3 = new OracleCommand("UPDATE
MIKEW_QUERY_TEST set ID = ?, NAME = ?, PHONE = ? WHERE ID = ?",
o_Connection);
o_Command3.Parameters.Add(new OracleParameter("ID",
OracleDbType.Number, 0, "ID"));
o_Command3.Parameters.Add(new OracleParameter("NAME",
OracleDbType.VarChar, 25, "NAME"));
o_Command3.Parameters.Add(new OracleParameter("PHONE",
OracleDbType.Number, 0, "PHONE"));
o_ParameterCollection = o_Command3.Parameters;
o_Parameter = o_ParameterCollection.Add("ID_Orig",
OracleDbType.Number, 0, "ID");
o_Parameter.SourceVersion = DataRowVersion.Original;
DDTek.Oracle.OracleDataAdapter o_DataAdapter = new
OracleDataAdapter();
o_DataAdapter.InsertCommand = o_Command1;
o_DataAdapter.DeleteCommand = o_Command2;
o_DataAdapter.UpdateCommand = o_Command3;
o_DataAdapter.Update(this._dataSet);
o_DataAdapter.Dispose();
DDTek.Oracle.OracleCommand o_Command = new OracleCommand("Select *
from MIKEW_QUERY_TEST", o_Connection);
o_DataAdapter = new OracleDataAdapter(o_Command);
this._dataSet.Clear();
o_DataAdapter.Fill(_dataSet);
dataGrid1.SetDataBinding(this._dataSet,
this._dataSet.Tables[0].TableName);
o_Connection.Close();
o_Connection.Dispose();
o_DataAdapter.Dispose();
o_Command.Dispose();
}
}
(through DataAdapter) working. I have the insert working just fine, but the
update/delete do not work. This is a win app if that matters. I get a
concurrency update (or delete) error saying that no rows are updated (or
deleted). Anyone have any idea what I could be doing wrong????
Thanks in advance!!
WebDevHokie
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button2;
private System.Data.DataSet _dataSet = new DataSet();
// puts the data in the datagrid
private void button1_Click(object sender, System.EventArgs e)
{
this._dataSet.Clear();
DDTek.Oracle.OracleConnection o_Connection = new
OracleConnection("Server Name=RPLANS;User ID=rplans_dev;Password=g00dwill");
o_Connection.Open();
DDTek.Oracle.OracleCommand o_Command = new OracleCommand("Select *
from MIKEW_QUERY_TEST", o_Connection);
DDTek.Oracle.OracleDataAdapter o_DataAdapter = new
OracleDataAdapter(o_Command);
o_DataAdapter.Fill(_dataSet);
dataGrid1.SetDataBinding(this._dataSet,
this._dataSet.Tables[0].TableName);
o_Connection.Close();
o_Connection.Dispose();
o_DataAdapter.Dispose();
o_Command.Dispose();
}
// performs the modification
private void button2_Click(object sender, System.EventArgs e)
{
DDTek.Oracle.OracleConnection o_Connection = new
OracleConnection("Server Name=Test_DB;User ID=Test_User;Password=Test");
DDTek.Oracle.OracleParameter o_Parameter;
o_Connection.Open();
// insert command
DDTek.Oracle.OracleCommand o_Command1 = new OracleCommand("Insert
into QUERY_TEST (ID, NAME, PHONE) values (?,?,?)", o_Connection);
o_Command1.Parameters.Add(new OracleParameter("ID",
OracleDbType.Number, 0, "ID"));
o_Command1.Parameters.Add(new OracleParameter("NAME",
OracleDbType.VarChar, 25, "NAME"));
o_Command1.Parameters.Add(new OracleParameter("PHONE",
OracleDbType.Number, 0, "PHONE"));
// delete command
DDTek.Oracle.OracleCommand o_Command2 = new OracleCommand("DELETE
from MIKEW_QUERY_TEST where ID = ?", o_Connection);
OracleParameterCollection o_ParameterCollection =
o_Command2.Parameters;
o_Parameter = new OracleParameter("ID", OracleDbType.Number, 0,
"ID");
o_Parameter.SourceVersion = DataRowVersion.Original;
o_Command2.Parameters.Add(o_Parameter);
// update command
DDTek.Oracle.OracleCommand o_Command3 = new OracleCommand("UPDATE
MIKEW_QUERY_TEST set ID = ?, NAME = ?, PHONE = ? WHERE ID = ?",
o_Connection);
o_Command3.Parameters.Add(new OracleParameter("ID",
OracleDbType.Number, 0, "ID"));
o_Command3.Parameters.Add(new OracleParameter("NAME",
OracleDbType.VarChar, 25, "NAME"));
o_Command3.Parameters.Add(new OracleParameter("PHONE",
OracleDbType.Number, 0, "PHONE"));
o_ParameterCollection = o_Command3.Parameters;
o_Parameter = o_ParameterCollection.Add("ID_Orig",
OracleDbType.Number, 0, "ID");
o_Parameter.SourceVersion = DataRowVersion.Original;
DDTek.Oracle.OracleDataAdapter o_DataAdapter = new
OracleDataAdapter();
o_DataAdapter.InsertCommand = o_Command1;
o_DataAdapter.DeleteCommand = o_Command2;
o_DataAdapter.UpdateCommand = o_Command3;
o_DataAdapter.Update(this._dataSet);
o_DataAdapter.Dispose();
DDTek.Oracle.OracleCommand o_Command = new OracleCommand("Select *
from MIKEW_QUERY_TEST", o_Connection);
o_DataAdapter = new OracleDataAdapter(o_Command);
this._dataSet.Clear();
o_DataAdapter.Fill(_dataSet);
dataGrid1.SetDataBinding(this._dataSet,
this._dataSet.Tables[0].TableName);
o_Connection.Close();
o_Connection.Dispose();
o_DataAdapter.Dispose();
o_Command.Dispose();
}
}