Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
Hello, I am having problems getting my data to "Stick" for want of a better term. I've stripped back my project to the following lines of code. When I run this the pressing of the button adds 10 records, using debug tools, I can see the dataset grow by 10 records each time. Once I close the program though, all the data disappears, and if I run it again I start adding blocks of 10 from 0 again. It's a single table in a database called ProjectA. Am I mssing something really, really basic or do I have a bigger problem?
 
namespace ProjectA
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            ProjectADataSetTableAdapters.tblCurrenciesTableAdapter curr = new ProjectA.ProjectADataSetTableAdapters.tblCurrenciesTableAdapter();
            ProjectADataSet.tblCurrenciesDataTable ds = new ProjectADataSet.tblCurrenciesDataTable();
            curr.Fill(ds);
 
            for (int i = 0; i < 10; i++)
            {
                ProjectADataSet.tblCurrenciesRow newRow = ds.NewtblCurrenciesRow();
                newRow.fldCurrencyID = "A" + i;
                newRow.fldCurrencyDescription = "AAAA" + i;
                ds.AddtblCurrenciesRow(newRow);
            }
 
            curr.Update(ds);
        }
    }
}
Posted 12-Sep-12 18:53pm
Edited 12-Sep-12 19:09pm
v3
Comments
Wes Aday at 13-Sep-12 16:38pm
   
From your comments back and forth with Mohamed Mitwalli it sounds more like that you are working with a local database and it's getting copied over with a fresh copy everytime that you run your application. Nothing to do with your code.
Stu Baby at 13-Sep-12 17:05pm
   
That makes a lot of sense, how do I solve this?
Stu Baby at 13-Sep-12 17:51pm
   
Hello Wes, is there an MSN document/webstie or your wisdom that you can direct me to that explains this all to me. Now I've got the debug directory database retaining the data, after closing visual studio and restarting. But then If I want to run a quick query on the data, I have to use a connection to the debug directory as the root directory continues to contain no data. Meanwhile all connections associated with the solution, continue to point to the database in the root directory, which all seems very counter-intuitive. Is this how it is supposed to work?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi ,
Check this Updated
 
        private void button1_Click(object sender, EventArgs e)
        {
            WindowsFormsApplication32.DataSet1TableAdapters.ProductTableAdapter adpt = new DataSet1TableAdapters.ProductTableAdapter();
            DataSet1 ds = new DataSet1();          
            adpt.Fill(ds.Product);
 
            for (int i = 0; i < 10; i++)
            {
             DataSet1.ProductRow newRow=   ds.Product.NewProductRow();
 
             newRow.name = "A" + i;
             ds.Product.AddProductRow(newRow);
            }
            adpt.Update(ds.Product);
            ds.AcceptChanges();
        }
Best Regards
M.Mitwalli
  Permalink  
v3
Comments
Stu Baby at 13-Sep-12 1:18am
   
The tablename doesn't come up with intellisence. I was assuming that this was because there was only one table in the database. If I type in ds.tblCurrencies, then it won't compile, so how do I actually enter what you are suggesting? Thanks for your input.
Mohamed Mitwalli at 13-Sep-12 1:35am
   
curr.Update(ds.Tables[0]); Check this
Stu Baby at 13-Sep-12 2:44am
   
Intellisense doesn't bring up Tables after ds., and typing it in causes an error.
Mohamed Mitwalli at 13-Sep-12 2:50am
   
ok just add to your code ds.AcceptChanges();
Stu Baby at 13-Sep-12 3:20am
   
Yeah, sorry, but I already ahve that. Don't know how I didn't get that in the posting. So does this mean my problem is "Bigger"
Mohamed Mitwalli at 13-Sep-12 3:29am
   
Let me get the things right .
First you create ProjectADataSet.xsd then you add your table tblCurrenciesTableAdapter and you supply the insert command , update ,delete and select Isn't
Stu Baby at 13-Sep-12 3:39am
   
THe code above is the entire project. Beyond this is a dataset, allowing strongly typed entry of ProjectADataSetTableAdapters.tblCurrenciesTableAdapter from the one single table inthe project. I'm trying to re load visual studio 2008, but it's coming up with an error and won't allow me to run a repair/install.
Mohamed Mitwalli at 13-Sep-12 4:09am
   
I make the same code with me and it's work fine ,Check the update solution
Stu Baby at 13-Sep-12 4:14am
   
http://visualstudiomagazine.com/blogs/tool-tracker/2012/05/dealing-with-local-databases-or-why-your-updates-dont-stick.aspx
 
I've just read this online, and now I'm completely confused. I thought I was i a sandbox, so to speak and could do what I want. I really appreciate your time here, and what do you mean by "Check the update solution" part?
Mohamed Mitwalli at 13-Sep-12 4:18am
   
i make like sample code and i tested and it work fine with so i believe the problem in your Dataset try to configure it again
private void button1_Click(object sender, EventArgs e)
{
WindowsFormsApplication32.DataSet1TableAdapters.ProductTableAdapter adpt = new DataSet1TableAdapters.ProductTableAdapter();
DataSet1 ds = new DataSet1();
adpt.Fill(ds.Product);

for (int i = 0; i < 10; i++)
{
DataSet1.ProductRow newRow= ds.Product.NewProductRow();

newRow.name = "A" + i;
ds.Product.AddProductRow(newRow);
}
adpt.Update(ds.Product);
ds.AcceptChanges();
}
Stu Baby at 13-Sep-12 4:19am
   
I've now successfully run a rebuild, but the same thing is still happening. do I have to do something to make my project "Live"?
Stu Baby at 13-Sep-12 4:34am
   
Mohamed, thank you so much for your time and effort. I'm so frustrated with what is going on, that i'm going to call it a day for now. I'm new to codeproject, so please advise how I should handle this question as I've spent 20 hours on this now, and I need to stop before I smash my computer. Once again, thank you so much for you efforts.
Mohamed Mitwalli at 13-Sep-12 4:44am
   
Stu did you see the example i have provided for you
Steps For solution
go add new item add dataset.xsd then right click choose addtableadpter Choose your conection then next add your Query from your table now you have created your own Table adpater Follow the Code i have provide in solution and it will work fine :) Hope this help this time .
Stu Baby at 13-Sep-12 4:58am
   
OK, my computer is still alive, and I've done what you suggested. So am I now doing something wrong in Visual Studio? I also did what the guy in the blog suggested at http://visualstudiomagazine.com/blogs/tool-tracker/2012/05/dealing-with-local-databases-or-why-your-updates-dont-stick.aspx and when I close the application, the data is there in the debug directory database. However, if I close visual studio, it goes away again and I have to start again to put our test data into the table. Is there a setting I'm supposed to activate or something like that?
Mohamed Mitwalli at 13-Sep-12 5:22am
   
If the data still not showing in Database
Do this
Go for your dataset then choose your table click proprieties Change the connection make sure you put the write conection
Stu Baby at 13-Sep-12 5:40am
   
C:\USERS\DEVELOPMENT\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\PROJECTA\PROJECTA\PROJECTA.MDF
 
C:\USERS\DEVELOPMENT\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\PROJECTA\PROJECTA\BIN\DEBUG\PROJECTA.MDF
 
These are the two connection properties and I don't see how these could have been mixed up. It's a new project, with nothing else going on
Mohamed Mitwalli at 13-Sep-12 6:30am
   
Create New one To the Attached database in your SQL management studio

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 Prakriti Goyal 242
2 Yogesh Kumar Tyagi 224
3 Sergey Alexandrovich Kryukov 158
4 CPallini 150
0 OriginalGriff 6,742
1 Sergey Alexandrovich Kryukov 5,479
2 Maciej Los 3,474
3 Peter Leow 3,313
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100