无法将数据保存到数据库中?

时间:2021-07-13 07:41:02

I'm creating my first database via c# and visual studio 2k12. I added new item, went throw all those setups and finally saw *.mdf. Then I added new table, added data and by drag&drop added components to form. Since here everything goes right. But then I made a button, which add new row to database. In datagridview seems everything okay, new row appeared. Then i closed window and made a look at database if everything is okay. Then I saw that database is disconnected and data nowhere. I use this code to add new raw.

我正在通过c#和visual studio 2k12创建我的第一个数据库。我添加了新项目,去抛出所有的设置,最后看到*.mdf。然后我添加了新的表,添加了数据,并通过拖放添加了组件到表单中。因为这里一切正常。然后我做了一个按钮,向数据库添加新行。在datagridview中看起来一切正常,出现了新行。然后我关闭窗口,查看数据库是否一切正常。然后我发现数据库是断开连接的,没有数据。我使用此代码添加新的raw。

private void button1_Click(object sender, EventArgs e)
    {
        Database1DataSet.MP3Row newMP3Row = database1DataSet.MP3.NewMP3Row();
        newMP3Row.path = "D://new/mp3";
        this.database1DataSet.MP3.Rows.Add(newMP3Row);
        this.mP3TableAdapter.Update(this.database1DataSet.MP3);
    }

Could someone tell me, where i made a mistake?

谁能告诉我,我哪里做错了?

2 个解决方案

#1


3  

Finally I finished this problem. My code is corect, but there was problem with database. I found documentm, which helped me solve my problem. Here is link, point 2: FAQ: My database isn't being updated, but no errors occurred in my application

最后我完成了这个问题。我的代码是corect的,但是数据库有问题。我找到了documentm,帮助我解决问题。这里是链接,第2点:FAQ:我的数据库没有更新,但是在我的应用程序中没有发生错误

#2


0  

Looks like you need a database1DataSet.Commit() or database1DataSet.SaveChanges()

看起来您需要一个database1DataSet.Commit()或database1DataSet.SaveChanges()

VS2012 will show you all options available there ;)

VS2012将向您展示所有可用的选项;

#1


3  

Finally I finished this problem. My code is corect, but there was problem with database. I found documentm, which helped me solve my problem. Here is link, point 2: FAQ: My database isn't being updated, but no errors occurred in my application

最后我完成了这个问题。我的代码是corect的,但是数据库有问题。我找到了documentm,帮助我解决问题。这里是链接,第2点:FAQ:我的数据库没有更新,但是在我的应用程序中没有发生错误

#2


0  

Looks like you need a database1DataSet.Commit() or database1DataSet.SaveChanges()

看起来您需要一个database1DataSet.Commit()或database1DataSet.SaveChanges()

VS2012 will show you all options available there ;)

VS2012将向您展示所有可用的选项;