TableAdapter Update problem

Hello, i have problem in my application.
I create dataset with single table. In MainForm i have 2 texboxes and update button.

This is code for update button:

[CODE]
Klient klient = new Klient();
klient.ShowDialog();

KlientDataSet dataSet = new KlientDataSet();

Serwis.KlientDataSet.KlienciRow klientRow = dataSet.Klienci.NewKlienciRow();
klientRow[0] = Guid.NewGuid();
klientRow[1] = klient.Imie;
klientRow[2] = klient.Nazwisko;

dataSet.Klienci.AddKlienciRow( klientRow );

int result = this.klienciTableAdapter1.Update( dataSet.Klienci );
[/CODE]

I got 1 in result variable so i think that database was updated. No my database was not updated.


I add another form to my app with droped table from tolbox. VS created textboxes and datanavigator. When im add newdata and click savedata my database not updating!

I reinstall vs and sql but my database still not updating.

What's wrong

Im using Visual Studio beta2 and SQL Express. My os is Windows 2003 SP1.

Sorry for my english ;)


Answer this question

TableAdapter Update problem

  • Michel Blairon

    That's why this is such an interesting issue.  There are multiple reports of the problem, yet the approach works in a simple application.

    I'm hoping that someone can provide steps to reproduce the problem, so I can investigate it.

    David Sceppa

    ADO.NET Program Manager

    Microsoft



  • Travis Shipley

     David Sceppa wrote:

    If you connect to a SQL Server database file in Visual Studio.NET 2005 Server Explorer and then create your Data Source using that connection, VS.NET will display a dialog asking the following question:

    "The connection you selected uses a local data file that is not in the current project. Would you like to add the file to your project and modify the connection "

    If you say "Yes", when you build the application VS.NET will copy the .mdf file into the application's output directory, where the executable file lives.  The design-time connection in Server Explorer will still point to the original .mdf file rather than the copy in your output directory.  This approach simplifies the process of packaging and deploying your application.  However, the approach has some interesting side effects.



    Hi David,
    Can you please highlight some advantages of saying "Yes" to the above dialog. Why would i want to give a local .mdf file to each user of my software


  • zombie_process

    Steve,

    No problem.  Please update this thread if you have more information regarding the original issue.

    Please post the question regarding the hierarchical binding in a new thread.  It helps with tracking answered/un-answered questions in the forum.  Thanks.

    David Sceppa
    ADO.NET Program Manager
    Microsoft

  • Lion_cl

    ADO.NET Program Manager

    I think you should be the one who can fix our prolem....
    So why do you ask for repro steps

    Or am i wrong

    Greetz

  • Michael Jozwik

    Could someone post repro steps so others can reproduce the problem and, hopefully, provide a solution   Focusing on sample tables like Northwind.Customers might speed things up and make sure everyone's working with the same schema.  Thanks.

    David Sceppa

    ADO.NET Program Manager

    Microsoft



  • Bharati Kumars

    I don't have a repro for your exact scenario, but I spoke to one of the VS.NET Program Managers and he offered a potential explanation.  The VS.NET team assures me that they'll discuss the behavior in an upcoming blog entry.  This may be the explanation for the behavior some are seeing.  I'd appreciate feedback from people on the thread on this response.  Does this explain the behavior you're seeing

    If you connect to a SQL Server database file in Visual Studio.NET 2005 Server Explorer and then create your Data Source using that connection, VS.NET will display a dialog asking the following question:

    "The connection you selected uses a local data file that is not in the current project. Would you like to add the file to your project and modify the connection "

    If you say "Yes", when you build the application VS.NET will copy the .mdf file into the application's output directory, where the executable file lives.  The design-time connection in Server Explorer will still point to the original .mdf file rather than the copy in your output directory.  This approach simplifies the process of packaging and deploying your application.  However, the approach has some interesting side effects.

    You can then run your code and successfully add/modify/delete rows in your code to change the contents of the .mdf file that resides in the output directory.  However, if you check the contents of the .mdf file through Server Explorer, you won't see the new data because you're looking at the original .mdf file. 

    There's another side effect of examining the .mdf file through Server Explorer.  The next time you build the application, VS.NET will copy the original .mdf file into the output directory again.  If you look at the .mdf file in Solution Explorer, you'll see that it's marked as "Copy if newer".  VS.NET checks timestamps in the original .mdf file to determine when to perform the copy.  This way, if you modify rows or schema in the original .mdf file, those changes will be available in the .mdf file in the output directory.  According to the VS.NET team, the .mdf file is marked as "Copy always" in Solution Explorer in post-Beta 2 builds.

    Say that your application creates a new row and submits it to your .mdf file using a TableAdapter, a DataAdapter, an INSERT INTO query or a stored procedure call.  You can execute that code, see that the return value indicates success, and even query the table to verify that the new row exists.  If you check the contents of the .mdf file in Server Explorer, you won't see the new row.  You'll also cause VS.NET to re-copy the .mdf file into the application's output directory, and the changes you made the last time you ran the application will be gone.

    These are the behaviors associated with saying "Yes" to that earlier dialog. 

    I hope this information proves helpful.

    David Sceppa

    ADO.NET Program Manager

    Microsoft



  • endless glitches newbie

    Carl,

    In a previous post in this same thread, I've described a scenario involving connecting to a SQL Server database file (.mdf) in Server Explorer that could cause this behavior.

    If you're working with a different scenario and can reproduce it in a small application, please provide steps so that someone can help.

    David Sceppa
    ADO.NET Program Manager
    Microsoft



  • Vitaliy Kochubiy

    hi. i am working on the same problem. havent got a solution yet, but reinstall win,vs and sql is nonsense....

    i keep you up to date if you want. did you find any solutions for that in the meantime

    greetz

  • MadAboutC#

    Hello Mr. Sceppa.

    The information you have provided is very interesting and useful. Thanks for that feedback!

    According to the thread problem here, i changed some code in my programs to use a ".update" command. Everything works fine, so i cant also reconstruct the problems "ghostek" and me had.

    Currently i try to find some informations, sourcecode or examples to add a "subtable" to the datagridview to make it hierarchical. But still without success...

    I ve heard that this would be possible.

    So, again thanks for your information.

    Best regards,
    Steve


  • InoS

    Dear Mr. Sceppa

    I have had the same update problem several times, I have always managed to fix it, but I do not know how. Could I send you some code I can’t post the code here since it’s not mine.

    Regards

    Carl-Johan Larsson


  • Pedro Costa

    what the hell....... ! !

    i tried also a little sample app, with a datagridview bound to a testtable. a button with just:

    TblTestTableAdapter.Update(Me.TestDataSet.Tables(0))

    and it works!! LOL :-D

    so, where was the problem i ask myself

    greetings from germany,
    dFeNsE


  • Kris4forums

    Anyone Plz help mi, i reinstaled Windows, VS, SQL and this still not working !
  • Narendran

    I created a small sample application to try to reproduce the problem, but I was able to submit the new row without a problem.  After calling Update, the new row was available in the database.

    So, I figured I'd ask for steps that would allow me to reproduce the problem.

    David Sceppa
    ADO.NET Program Manager
    Microsoft



  • philmagice

    Hi, I got the same problem.
    The program didn't work properly even though I constructed it using the bult-in Wizards.

  • TableAdapter Update problem