PC Review


Reply
Thread Tools Rate Thread

Adapter.Update does not change database

 
 
=?Utf-8?B?Um9jaw==?=
Guest
Posts: n/a
 
      23rd Nov 2005
I am trying to enter a new row into a test database and have been
unsuccessful. The code compiles fine and runs with out runtime errors,
however after closing the form and checking the database it is the same.
Since this is my first time using a database any additional suggestions that
I should check on that are not obvious in my code snippet will be useful!

Sincere thanks,
Rock


private void button1_Click(object sender, EventArgs e)
{
// Create new entry
myDatabaseDataSet.UserNamesRow user =
myDatabaseDataSet.UserNames.NewUserNamesRow();
user.First = firstTextBox.Text;
user.Last = lastTextBox.Text;
myDatabaseDataSet.UserNames.Rows.Add(user);

// Save new entry
this.Validate();
this.userNamesBindingSource.EndEdit();
if(user.RowState != DataRowState.Added)
MessageBox.Show("No Changes Seen in DataSEt");
int result =
this.userNamesTableAdapter.Update(this.myDatabaseDataSet.UserNames);

//Display # of updated rows
MessageBox.Show(result.ToString());
}
 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      24th Nov 2005
Rock,

Does your database table not have a primary key, mostly it does not work if
that is not supported.

Cor

"Rock" <(E-Mail Removed)> schreef in bericht
news:07F2EDFF-A44A-4476-BD5D-(E-Mail Removed)...
>I am trying to enter a new row into a test database and have been
> unsuccessful. The code compiles fine and runs with out runtime errors,
> however after closing the form and checking the database it is the same.
> Since this is my first time using a database any additional suggestions
> that
> I should check on that are not obvious in my code snippet will be useful!
>
> Sincere thanks,
> Rock
>
>
> private void button1_Click(object sender, EventArgs e)
> {
> // Create new entry
> myDatabaseDataSet.UserNamesRow user =
> myDatabaseDataSet.UserNames.NewUserNamesRow();
> user.First = firstTextBox.Text;
> user.Last = lastTextBox.Text;
> myDatabaseDataSet.UserNames.Rows.Add(user);
>
> // Save new entry
> this.Validate();
> this.userNamesBindingSource.EndEdit();
> if(user.RowState != DataRowState.Added)
> MessageBox.Show("No Changes Seen in DataSEt");
> int result =
> this.userNamesTableAdapter.Update(this.myDatabaseDataSet.UserNames);
>
> //Display # of updated rows
> MessageBox.Show(result.ToString());
> }



 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      24th Nov 2005
Hi,

"Rock" <(E-Mail Removed)> wrote in message
news:07F2EDFF-A44A-4476-BD5D-(E-Mail Removed)...
>I am trying to enter a new row into a test database and have been
> unsuccessful. The code compiles fine and runs with out runtime errors,
> however after closing the form and checking the database it is the same.
> Since this is my first time using a database any additional suggestions
> that
> I should check on that are not obvious in my code snippet will be useful!


The code looks ok.

What's the value of "result" after update ? What DB are you using ?

HTH,
Greetings


>
> Sincere thanks,
> Rock
>
>
> private void button1_Click(object sender, EventArgs e)
> {
> // Create new entry
> myDatabaseDataSet.UserNamesRow user =
> myDatabaseDataSet.UserNames.NewUserNamesRow();
> user.First = firstTextBox.Text;
> user.Last = lastTextBox.Text;
> myDatabaseDataSet.UserNames.Rows.Add(user);
>
> // Save new entry
> this.Validate();
> this.userNamesBindingSource.EndEdit();
> if(user.RowState != DataRowState.Added)
> MessageBox.Show("No Changes Seen in DataSEt");
> int result =
> this.userNamesTableAdapter.Update(this.myDatabaseDataSet.UserNames);
>
> //Display # of updated rows
> MessageBox.Show(result.ToString());
> }



 
Reply With Quote
 
=?Utf-8?B?Um9jaw==?=
Guest
Posts: n/a
 
      28th Nov 2005
Thanks for responding to my question. Yes I have a primary key assigned and
the value of "result" is, 1. And as for the type of database, I am not
entirely sure how much info I can give but I will try: it is a SQL Database
located on my computer (.mdf) there is only this one table that I am trying
to add to. Lastly, the VS project was just started from scratch so all
variable settings are at there defaults as to try and eliminate any variables.

I have been following examples to the T and have had no luck, I hope you can
find or recall things to try so I can get this thing going!

Sincere thanks,
Rock
 
Reply With Quote
 
=?Utf-8?B?Um9jaw==?=
Guest
Posts: n/a
 
      28th Nov 2005
Thanks for responding to my question. Yes I have a primary key assigned and
the value of "result" is, 1. And as for the type of database, I am not
entirely sure how much info I can give but I will try: it is a SQL Database
located on my computer (.mdf) there is only this one table that I am trying
to add to. Lastly, the VS project was just started from scratch so all
variable settings are at there defaults as to try and eliminate any variables.

I have been following examples to the T and have had no luck, I hope you can
find or recall things to try so I can get this thing going!

Sorry for the redundancy.

Sincere thanks,
Rock


PS. Is there an read-only setting that would allow this to happen? Where
everything looks like it is updating and going well but then the database
just doesn't take the changes.
 
Reply With Quote
 
=?Utf-8?B?Um9jaw==?=
Guest
Posts: n/a
 
      28th Nov 2005
Thanks for responding to my question. Yes I have a primary key assigned and
the value of "result" is, 1. And as for the type of database, I am not
entirely sure how much info I can give but I will try: it is a SQL Database
located on my computer (.mdf) there is only this one table that I am trying
to add to. Lastly, the VS project was just started from scratch so all
variable settings are at there defaults as to try and eliminate any variables.

I have been following examples to the T and have had no luck, I hope you can
find or recall things to try so I can get this thing going!

Sincere thanks,
Rock

PS. Is there any things that would cause the database to be read-only? Where
everything seems to go fine with the update but then the database just
doesn't take the changes.
 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      28th Nov 2005
Hi,

"Rock" <(E-Mail Removed)> wrote in message
news:85765D94-0FEC-445C-850B-(E-Mail Removed)...
> Thanks for responding to my question. Yes I have a primary key assigned
> and
> the value of "result" is, 1. And as for the type of database, I am not
> entirely sure how much info I can give but I will try: it is a SQL
> Database
> located on my computer (.mdf) there is only this one table that I am
> trying
> to add to. Lastly, the VS project was just started from scratch so all
> variable settings are at there defaults as to try and eliminate any
> variables.
>
> I have been following examples to the T and have had no luck, I hope you
> can
> find or recall things to try so I can get this thing going!


If result == 1 then i think there's little chance the update failed.

Is the .mdf file part of the VS project (visible in solution explorer) ?

If so, then most likely it's copied to bin/debug each time your app starts
and that's the one used by your app. But the next time your app starts it
gets overwritten and all previous changes made are lost.

An option is to change "|DataDirectory|\yourdb.mdf" into "..\...\yourdb.mdf"
within connectionString inside app.config file. This way it will always use
the project database (instead of a new copy)

HTH,
Greetings



>
> Sorry for the redundancy.
>
> Sincere thanks,
> Rock
>
>
> PS. Is there an read-only setting that would allow this to happen? Where
> everything looks like it is updating and going well but then the database
> just doesn't take the changes.



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      28th Nov 2005
Rock,

Let I ask my question in another way, what is the primary key. I don't see
you setting it?

Cor


 
Reply With Quote
 
=?Utf-8?B?Um9jaw==?=
Guest
Posts: n/a
 
      29th Nov 2005
You have found what I have overlooked being new to SQL databases in VStudio.
And I can't thank you enough for getting rid of this headache. Changing the
directory is still a little fuzzy; could you give detailed steps describing
where I can go about changing this?

Sincere thanks,
Rock
 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      29th Nov 2005
Hi,

"Rock" <(E-Mail Removed)> wrote in message
news:E4F7C65A-40E3-4A07-8E23-(E-Mail Removed)...
> You have found what I have overlooked being new to SQL databases in
> VStudio.
> And I can't thank you enough for getting rid of this headache. Changing
> the
> directory is still a little fuzzy; could you give detailed steps
> describing
> where I can go about changing this?


I'm new to this too, i'm not sure if i can tell you anything more then i
already did.

Check if you have a file called app.config (solution explorer).
Open it and look if you have a tag like <connectionStrings>.
Within that tag multiple connection strings can be defined, there should be
one.
Within that connectionString there should be something like
"...AttachDbFileName=|DataDirectory|\yourdb.mdf...".
Change it into "...AttachDbFileName=..\..\yourdb.mdf...".

If this doesn't work explain what's different and what version of vs you're
using.

Greetings

>
> Sincere thanks,
> Rock



 
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
change the control souce and it does not update database? Yoshie Microsoft Access Forms 1 8th Jan 2009 11:23 PM
TableAdapter.Update() does not really change the database dani kotlar Microsoft C# .NET 5 29th Jan 2007 05:56 AM
Adapter.Update() problem with Access Database relationship divisortheory Microsoft ADO .NET 1 10th Jan 2007 06:45 AM
How to change the database schema by data adapter? barbara_dave@yahoo.com Microsoft VB .NET 1 17th Jun 2005 08:45 AM
Update Parameter Query to change a Default Value in Database structure Harry Kramm Microsoft Access Queries 0 22nd Sep 2003 03:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 PM.