Here you go.
//
// daTelephone
//
this.daTelephone.DeleteCommand =
this.oleDbDeleteCommand1;
this.daTelephone.InsertCommand =
this.oleDbInsertCommand1;
this.daTelephone.SelectCommand =
this.oleDbSelectCommand1;
this.daTelephone.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Telephone", new
System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("FirstName", "FirstName"),
new System.Data.Common.DataColumnMapping("LastName", "LastName"),
new System.Data.Common.DataColumnMapping("PhoneNumber", "PhoneNumber"),
new System.Data.Common.DataColumnMapping("Say", "Say"),
new System.Data.Common.DataColumnMapping("SayFileName", "SayFileName"),
new System.Data.Common.DataColumnMapping("SortOrder", "SortOrder"),
new System.Data.Common.DataColumnMapping("theIndex", "theIndex")})});
this.daTelephone.UpdateCommand =
this.oleDbUpdateCommand1;
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText = "DELETE FROM
Telephone WHERE (theIndex = ?)";
this.oleDbDeleteCommand1.Connection = this.cn;
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_theIndex",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "theIndex", System.Data.DataRowVersion.Original, null));
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = "INSERT INTO
Telephone(FirstName, LastName, PhoneNumber, Say, SayFileName, SortOrd" +
"er) VALUES (?, ?, ?, ?, ?, ?)";
this.oleDbInsertCommand1.Connection = this.cn;
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 50, "FirstName"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 50, "LastName"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("PhoneNumber",
System.Data.OleDb.OleDbType.VarWChar, 50, "PhoneNumber"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Say",
System.Data.OleDb.OleDbType.VarWChar, 50, "Say"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("SayFileName",
System.Data.OleDb.OleDbType.VarWChar, 50, "SayFileName"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("SortOrder",
System.Data.OleDb.OleDbType.Integer, 0, "SortOrder"));
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT
FirstName, LastName, PhoneNumber, Say, SayFileName, SortOrder, theIndex FR"
+
"OM Telephone";
this.oleDbSelectCommand1.Connection = this.cn;
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = "UPDATE
Telephone SET FirstName = ?, LastName = ?, PhoneNumber = ?, Say = ?, SayFi"
+
"leName = ?, SortOrder = ? WHERE (theIndex =
?)";
this.oleDbUpdateCommand1.Connection = this.cn;
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 50, "FirstName"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 50, "LastName"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("PhoneNumber",
System.Data.OleDb.OleDbType.VarWChar, 50, "PhoneNumber"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Say",
System.Data.OleDb.OleDbType.VarWChar, 50, "Say"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("SayFileName",
System.Data.OleDb.OleDbType.VarWChar, 50, "SayFileName"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("SortOrder",
System.Data.OleDb.OleDbType.Integer, 0, "SortOrder"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_theIndex",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "theIndex", System.Data.DataRowVersion.Original, null));
Trey said:
Of course I meant that it corrupted the data table and when I did a
DataAdapter.Update it correcupted the Database!
I have a database with this data in it for one of the tables
id FirstName LastName Say filename SortOrder
-- ---------- ---------- ---- --------- ------ --
--
1 Trey Weaver Trey say1.wav 1
2 Susan Weaver Susan say3.wav 2
3 Sam Smith Sammy say21.wav 3
4 Bill Smith Billy say4.wav
4
After doing these commands.
dr1.BeginEdit()
dr1[SortOrder} = 3;
dr1.EndEdit();
dr2.BeginEdit()
dr2[SortOrder} = 2;
dr2.EndEdit();
SaveData(); // updates the data adapter and table
The data now looks like this.
id FirstName LastName Say filename SortOrder
-- ---------- ---------- ---- --------- ------ --
--
1 Sam Smith Sammy say21.wav 2
// this is a duplicate
2 Susan Weaver Susan say3.wav 3
3 Sam Smith Sammy say21.wav 2
4 Bill Smith Billy say4.wav
4
I can set a breakpoint before and after this code check the database using
access. So I am confident that it is this code that causes the problem.
Notice that I never changed the FirstName field but yet it got changed in
the DataTable.
And Yes! I do have the datagrid connected to the dataview.
William Ryan eMVP said:
Trey:
The DataView doesn't give a hoot about the DB once you've created it. For
all it knows, the database who's data has populated it may not exist any
more. If anything is causing a corruption..it's got to be either your
update logic, some other code in the program or a corrupt database file.
I've seen this 'reported' before when people had stuff bound to a datagrid
and were using position in the grid as though it matched the underlying
datatable. That may or may not be the case based on sorting, but Something
has to send the update back to a database in order for anything to be
changed, and DataView's simply don't have that functionality. They
physically can't change a database so it's got to be your update logic..
HTH,
Bill