PC Review


Reply
Thread Tools Rate Thread

Bindings And Database Updates - ADO.NET

 
 
Darryn Ross
Guest
Posts: n/a
 
      23rd Jul 2003
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


 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      23rd Jul 2003
Darryn
Your controls are not bound to the 'database', they are bound to a dataset
(which is a disconnected, in-memory copy of the data from your database)
When you change the text in the textboxes, you are updating the dataset.
In order to update the database, you must call the Update method of your
DataAdaptor (DtlsAdapter.Update)
Note also that you should close the connection immediately after call the
Fill method.
Stephen

"Darryn Ross" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Darryn Ross
Guest
Posts: n/a
 
      24th Jul 2003
Stephen,

As you can see from my code i submitted, i am updating the dataset
through the adapter. That is not where my problem is, the problem is
that the information in my text fields is not changing even if i change
the text thats in them, this has been noted as a comment in my code
'//This is not changing'. The system isn't picking up the changes i make
to the text boxes and thus i think it has something to do with me
binding them to the dataset, this is causing the same information to be
saved each time.

Darryn


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database updates pfdubz Microsoft Excel Misc 2 16th Sep 2009 11:00 PM
Key bindings Travis Windows XP Customization 1 15th Jun 2004 01:24 AM
Database file name change causes issues with database design updates Michael Microsoft Access Security 1 12th Jun 2004 11:37 PM
odd Bindings Samuel Microsoft Dot NET Framework Forms 1 10th Sep 2003 05:46 PM
TCP bindings Seb_Lz Windows XP Networking 2 30th Aug 2003 07:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 AM.