简体   繁体   English

在Visual Studio Express 2012(C#)中更新LocalDB文件

[英]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. 在进行了一些研究之后,我偶然发现了LocalDB以及它对我的使用方式,从而决定了需要一个数据库的应用程序。

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. 为了测试这个新系统,我创建了一个测试应用程序,其唯一目的是连接到LocalDB数据库,然后检查可用于通过Code处理数据的各种命令。

I followed a guide to create the database, add it into Visual Studio, and then create a data connection. 我按照指南创建数据库,将其添加到Visual Studio中,然后创建数据连接。

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. visual studio实际上维护两个db文件。 one is in solution folder and other in bin folder. 一个在解决方案文件夹中,另一个在bin文件夹中。 your data is saved in db file of bin folder while you're trying to open file from solutions folder. 当您尝试从解决方案文件夹中打开文件时,您的数据将保存在bin文件夹的db文件中。 try to open db file from bin directory. 尝试从bin目录中打开db文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio Express 2012 for Windows 8中实现C#中的枚举 - Implementing enum in C# in Visual Studio Express 2012 for Windows 8 视觉工作室2010快递和2012年快递开放ac#项目的差异 - Differences with visual studio 2010 express and 2012 express for opening a c# project Microsoft Visual Studio 2012无法在c#文件中设置断点 - Microsoft Visual Studio 2012 cannot set breakpoint in c# file 无法在Visual Studio 2012中加载文件或程序集,C# - Could not load file or assembly in Visual Studio 2012, C# Visual Studio 2012 - C#:从资源中读取“.txt”文件 - Visual Studio 2012 - C#: Reading a '.txt' File From Resources 在 Visual Studio 2012 中的 C# 项目中更改文件完整路径 - Change file full path in a C# project in Visual studio 2012 C#Visual Studio:将列添加到localdb重设所有数据 - C# Visual studio : adding columns to localdb reset all data 在ASP.NET C中将数据插入Visual Studio LocalDB# - Insert data into Visual Studio LocalDB in ASP.NET C# Visual Studio 2012 Express C#为什么没有“使用组织”菜单选项? - Visual Studio 2012 Express C# Why do I have no “Organize Using” menu option? 似乎无法正确将Helix Toolkit添加到我的C#(Visual Studio Express 2012)项目中 - Can't seem to correctly add Helix Toolkit to my C# (Visual Studio Express 2012) project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM