Concurrency Violation

cheezy

Newcomer
Joined
Apr 11, 2003
Messages
13
Location
Tulsa, Oklahoma
Hi:

I have another conundrum that is causing me trouble. I want to bring up a simple table in Oracle into a dataGrid on a Form and be able to change various fields on the dataGrid and then save the changes back to the database.

Using the following code, I am able to retrieve the data from the oracle table, but when I make a change to the data, I keep getting "Concurrency violation: the UpdateCommand affected 0 records." when I click the “button1” button.

Can anyone see what I am doing wrong? Thanks again in advance; this forum has helped me greatly in the recent past, and more than once.

UPDATE: I think this is in part due to my oledb connection closing.


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace fdm2
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private OleDbDataAdapter adapter1;
private System.Data.DataSet ds1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1;
private OleDbParameter workParam1 = null;
private OleDbParameter workParam2 = null;
private OleDbParameter workParam3 = null;
private OleDbParameter workParam4 = null;
public static string strConnectionDetails = "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=git2.raptor;Extended Properties=\"\"";


public Form1()
{
InitializeComponent();
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
ds1 = new System.Data.DataSet();
OleDbConnection ODC = new OleDbConnection(strConnectionDetails);
label1.Text = null;
try
{

adapter1 = new OleDbDataAdapter();
adapter1.SelectCommand = new OleDbCommand("select” + “event_ref_no,prob_reg_no,delay_dt,prob_comm,fix_comm,attr_code, ata_chap,ata_sub_chap from de_preraw order by prob_reg_no,delay_dt",ODC);
adapter1.Fill(ds1,"newdata");
adapter1.UpdateCommand = new System.Data.OleDb.OleDbCommand("update de_preraw "
+ " set attr_code = :p1, "
+ " ata_chap = :p2 , "
+ " ata_sub_chap= :p3 "
+ " where event_ref_no = :p4", ODC);

workParam4 = adapter1.UpdateCommand.Parameters.Add(":p4",OleDbType.BigInt);
workParam4.SourceColumn = "EVENT_REF_NO";
workParam4.SourceVersion = DataRowVersion.Original;

workParam1 = adapter1.UpdateCommand.Parameters.Add(":p1",OleDbType.Char,1);
workParam1.SourceColumn = "ATTR_CODE";
workParam1.SourceVersion = DataRowVersion.Current;

workParam2 = adapter1.UpdateCommand.Parameters.Add(":p2",OleDbType.Integer);
workParam2.SourceColumn = "ATA_CHAP";
workParam2.SourceVersion = DataRowVersion.Current;

workParam3 = adapter1.UpdateCommand.Parameters.Add(":p3",OleDbType.Integer);
workParam3.SourceColumn = "ATA_SUB_CHAP";
workParam3.SourceVersion = DataRowVersion.Current;
}
catch (OleDbException ex)
{
System.Windows.Forms.MessageBox.Show("exc: " + ex.ToString() );
}
finally
{
if(ODC.State.ToString() == "Open" )
ODC.Close();
}
dataGrid1.DataSource = ds1;
}

private void button1_Click(object sender, System.EventArgs e)
{
adapter1.Update(ds1,"newdata");
}
 
Back
Top