Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

Scheduled Pinned Locked Moved C#
databasecsharpmysqldotnetsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 3950922
    wrote on last edited by
    #1

    Hi there, When I use the following code below I get and error called , "concurrency violation" and the database is not updated. I am able to connect and retrieve data. but I cannot update the data from the datatable of dataset. I am new to datagridview and datasets. I am using Mysql 5.0 and Mysql connector .NET 5.1.2 I read many articles on updating the dataset and almost tried everything , but It does not work, I can update to Mysql database using update commands. But I want to use Dataset or dataadapter update to make it more simpler. public partial class Form1 : Form { DataSet ds = new DataSet(); MySqlDataAdapter da; DataTable dt = new DataTable(); string tabname; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { CreateMySqlCommand(); } // Connecting to db and filling the datagridview with data. public void CreateMySqlCommand() { MySqlConnection myConnection = new MySqlConnection("Persist Security Info=False;userid=root;password=XXXX;database=test;server=terrain"); myConnection.Open(); MySqlTransaction myTrans = myConnection.BeginTransaction(); string mySelectQuery = "SELECT * FROM patient_master"; MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection,myTrans); da = new MySqlDataAdapter(mySelectQuery ,myConnection) ; MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(da); da.Fill(ds); dt = ds.Tables[0]; DataRow row; row = dt.Rows[0]; int lirow = dt.Rows.Count; string mrno = row["MRNO"].ToString(); string patname = row["GIVEN_NAME"].ToString(); dataGridView1.DataSource = ds; dataGridView1.DataMember = ds.Tables[0].ToString(); tabname = dt.TableName; int y = 0; foreach (DataGridViewRow ro in dataGridView1.Rows) { if (y % 2 == 0) ro.DefaultCellStyle.BackColor = Color.Red; y++; } } // code on the button to update the datadapter private void button1_Click(object sender, EventArgs e) { da.Update(ds, tabname); } } }

    C 1 Reply Last reply
    0
    • U User 3950922

      Hi there, When I use the following code below I get and error called , "concurrency violation" and the database is not updated. I am able to connect and retrieve data. but I cannot update the data from the datatable of dataset. I am new to datagridview and datasets. I am using Mysql 5.0 and Mysql connector .NET 5.1.2 I read many articles on updating the dataset and almost tried everything , but It does not work, I can update to Mysql database using update commands. But I want to use Dataset or dataadapter update to make it more simpler. public partial class Form1 : Form { DataSet ds = new DataSet(); MySqlDataAdapter da; DataTable dt = new DataTable(); string tabname; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { CreateMySqlCommand(); } // Connecting to db and filling the datagridview with data. public void CreateMySqlCommand() { MySqlConnection myConnection = new MySqlConnection("Persist Security Info=False;userid=root;password=XXXX;database=test;server=terrain"); myConnection.Open(); MySqlTransaction myTrans = myConnection.BeginTransaction(); string mySelectQuery = "SELECT * FROM patient_master"; MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection,myTrans); da = new MySqlDataAdapter(mySelectQuery ,myConnection) ; MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(da); da.Fill(ds); dt = ds.Tables[0]; DataRow row; row = dt.Rows[0]; int lirow = dt.Rows.Count; string mrno = row["MRNO"].ToString(); string patname = row["GIVEN_NAME"].ToString(); dataGridView1.DataSource = ds; dataGridView1.DataMember = ds.Tables[0].ToString(); tabname = dt.TableName; int y = 0; foreach (DataGridViewRow ro in dataGridView1.Rows) { if (y % 2 == 0) ro.DefaultCellStyle.BackColor = Color.Red; y++; } } // code on the button to update the datadapter private void button1_Click(object sender, EventArgs e) { da.Update(ds, tabname); } } }

      C Offline
      C Offline
      Claudia P
      wrote on last edited by
      #2

      I have the same problem. Any solution?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups