D
Darryn Ross
Hi,
I am trying to create am update procedure in my application for my access
database records, the controls (text boxes) on my form are bound to the
database, when i go to apply the changes i have made to the fields on the
form, the original details are restored and all my changes are lost, I know
it has something to do with the binding i have setup but am unsure how to
get around it.
Here is my binding code followed by the update procedure i use...
SqlSelect = "Select * From tbl WHERE Code=" + "'" + StrCode + "'" ;
//Connection details
DtlsConnection.ConnectionString = StrConnectionPath ;
DtlsConnection.Open() ;
//Command details
DtlsCommand.CommandText = SqlSelect ;
DtlsCommand.Connection = DtlsConnection ;
//Adapter details
DtlsAdapter.SelectCommand = SelectDtlsCommand ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;
//Binding text boxes to their specified database fields
txtName.DataBindings.Add(new Binding
("Text", DtlsDs, "tbl.Name")) ;
txtType.DataBindings.Add(new Binding
("Text", DtlsDs, "tbl.Type")) ;
DtlsConnection.Close() ;
/*--------------------------------------------------------------------------
-----------*/
DtlsConnection.ConnectionString = StrConnectionPath ;
DtlsConnection.Open() ;
DtlsCommand.CommandText = "Select * From tbl" ;
DtlsCommand.Connection = DtlsConnection ;
DtlsAdapter.SelectCommand = DtlsCommand ;
DtlsAdapterInsertCommand() ;
DtlsAdapterUpdateCommand() ;
DtlsAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;
DataRow tblRow ;
tblRow = DtlsDs.Tables["tbl"].Rows.Find(StrCode) ;
tblRow.BeginEdit() ;
try {
tblRow["Name"] = txtName.Text ; //this is not changing??
tblRow["Type"] = txtType.Text ; //this is not changing??
tblRow.EndEdit() ;
DtlsAdapter.Update(DtlsDs, "tbl") ;
}
catch(Exception e) {
MessageBox.Show(e.Message, "Error Updating Record", MessageBoxButtons.OK,
MessageBoxIcon.Error) ;
tblRow.CancelEdit() ;
}
Any help would be appreciated...
Kind Regards
Darryn Ross
I am trying to create am update procedure in my application for my access
database records, the controls (text boxes) on my form are bound to the
database, when i go to apply the changes i have made to the fields on the
form, the original details are restored and all my changes are lost, I know
it has something to do with the binding i have setup but am unsure how to
get around it.
Here is my binding code followed by the update procedure i use...
SqlSelect = "Select * From tbl WHERE Code=" + "'" + StrCode + "'" ;
//Connection details
DtlsConnection.ConnectionString = StrConnectionPath ;
DtlsConnection.Open() ;
//Command details
DtlsCommand.CommandText = SqlSelect ;
DtlsCommand.Connection = DtlsConnection ;
//Adapter details
DtlsAdapter.SelectCommand = SelectDtlsCommand ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;
//Binding text boxes to their specified database fields
txtName.DataBindings.Add(new Binding
("Text", DtlsDs, "tbl.Name")) ;
txtType.DataBindings.Add(new Binding
("Text", DtlsDs, "tbl.Type")) ;
DtlsConnection.Close() ;
/*--------------------------------------------------------------------------
-----------*/
DtlsConnection.ConnectionString = StrConnectionPath ;
DtlsConnection.Open() ;
DtlsCommand.CommandText = "Select * From tbl" ;
DtlsCommand.Connection = DtlsConnection ;
DtlsAdapter.SelectCommand = DtlsCommand ;
DtlsAdapterInsertCommand() ;
DtlsAdapterUpdateCommand() ;
DtlsAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;
DataRow tblRow ;
tblRow = DtlsDs.Tables["tbl"].Rows.Find(StrCode) ;
tblRow.BeginEdit() ;
try {
tblRow["Name"] = txtName.Text ; //this is not changing??
tblRow["Type"] = txtType.Text ; //this is not changing??
tblRow.EndEdit() ;
DtlsAdapter.Update(DtlsDs, "tbl") ;
}
catch(Exception e) {
MessageBox.Show(e.Message, "Error Updating Record", MessageBoxButtons.OK,
MessageBoxIcon.Error) ;
tblRow.CancelEdit() ;
}
Any help would be appreciated...
Kind Regards
Darryn Ross