Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?

C#
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
Updated 12-Sep-12 19:09pm
v3
Comments
[no name] 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 13-Sep-12 17:05pm    
That makes a lot of sense, how do I solve this?
Stu Baby 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

Hi ,
Check this Updated
C#
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
 
Share this answer
 
v3
Comments
Stu Baby 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 13-Sep-12 1:35am    
curr.Update(ds.Tables[0]); Check this
Stu Baby 13-Sep-12 2:44am    
Intellisense doesn't bring up Tables after ds., and typing it in causes an error.
Mohamed Mitwalli 13-Sep-12 2:50am    
ok just add to your code ds.AcceptChanges();
Stu Baby 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"

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900