简体   繁体   中英

Updating a LocalDB file in Visual Studio Express 2012 (C#)

I have been building an application where I decided that a database was needed, after doing a little research I stumbled across LocalDB and how it could be of use to me.

To test this new system I have created a test application with the sole purpose of connecting to a LocalDB database and then checking the various commands that can be used to manipulate data through Code.

I followed a guide to create the database, add it into Visual Studio, and then create a data connection.

After doing this, and adding a view of the database to the form, I then created a button with the following code.

    private void btnTest_Click(object sender, EventArgs e)
    {
        DataRow newLocationRow = dBTestSet.exitLogsLocation.NewRow();

        newLocationRow["locationName"] = "Test";
        newLocationRow["fileLocation"] = "Test";
        newLocationRow["logCount"] = 4;

        dBTestSet.exitLogsLocation.Rows.Add(newLocationRow);

        exitLogsLocationTableAdapter.Update(newLocationRow);

    }

With the purpose literally being to add a new row to the table and then save to the database.

This is the point where I get stuck. The program adds the new row to the data grid view thats on the form, but doesnt actually commit to the database.

I think I'm probably missing something really basic here, but after looking online for any explanation, I am at a loss.

I tried to add some pictures to aid with this query but I do not have enough reputation to do so, I would upload them to an image sharing site, but I'm not sure if that's allowed.

Apologies if this is a silly question, and by all means please ask me for any information I may have missed out.

Thanks in advance,

Will

visual studio actually maintains two db file. one is in solution folder and other in bin folder. your data is saved in db file of bin folder while you're trying to open file from solutions folder. try to open db file from bin directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM