-->I have next structure of the table
Code: Select all
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| Name | varchar(100) | YES | | NULL | |
| Address | varchar(100) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
LoadMethod()
Code: Select all
{
uniDataAdapter1.FillSchema(dataTable1, SchemaType.Source);
uniDataAdapter1.Fill(dataTable1);
}
Code: Select all
InsertRecord(string name, string address)
{
……………
DataRow row = dataTable1.NewRow();
//row["id"] = GetAutoIncrementValue();
row["name"] = name;
row["address"] = address;
dataTable1.Rows.Add(row);
uniDataAdapter1.Update(dataTable1);
……………
}
Code: Select all
DeleteRecord()
{
……
gridView1.DeleteSelectedRows();
try
{
uniDataAdapter1.Update(dataTable1);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "MYSQL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
……
}
Code: Select all
mysql> select * from test;
+-----+-------------+--------------+
| id | Name | Address |
+-----+-------------+--------------+
| 274 | Lev Tolstoy | Bukgakova 12 |
+-----+-------------+--------------+
1 row in set (0.00 sec)
Concurrency violation: the DeleteCommand affected {0} of the expected {1} records.
-->For solving problem I use GetAutoIncrementValue():
Code: Select all
GetAutoIncrementValue()
{
…………………
MySqlCommand command = connection.CreateCommand();
command.CommandText = String.Format("select auto_increment from information_schema.TABLES where TABLE_NAME='test' and TABLE_SCHEMA='devart';");
object result = command.ExecuteScalar();
if (result!=null)
{
autoIncrementValue = Convert.ToInt32(result);
}
……………..
return autoIncrementValue;
}
Code: Select all
.....
row["id"] = GetAutoIncrementValue();
.....
How I can synchronize the local auto_increment value and the auto_increment value of the real data base, using universal components without GetAutoIncrementValue()?