插入到mdf数据库中 [英] insert into mdf database

查看:87
本文介绍了插入到mdf数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据插入.mdf数据库

我的连接

i want to insert data into .mdf database
this my connection

SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True;User Instance=True");





这是添加代码



and this is add code

cmd.CommandText = "insert into deviceProblem(id,clientName,receiptDate,deliveryDate"+
                    ",deviceNumber,deviceType,deviceProb,price) " + 
                    "values(" + Convert.ToInt64(id.Text) + ",'" + clientName.Text + "','" 
                    + maskedTextBox1.Text + "','" + maskedTextBox2.Text + "'," 
                    + Convert.ToInt64(deviceId.Text) + ",'" + deviceType.Text + "','" + problem.Text + "'," + price.Text + ")";
                    cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() == 1)
                    {
                        MessageBox.Show("success" + id.Text);
                    }





成功出现但是当mdf数据库中没有关闭程序时

??



success appears but when close program nothing in mdf database
??

推荐答案

右键单击解决方案资源管理器中的mdf文件,然后转到属性>构建选项=>如果是较新的选项,请选择copy,并确保检查正确的数据库文件。如果您在调试模式下运行,请转到Bin \Debug文件夹并检查其中的mdf文件,如果您在发布模式下运行,则需要检查Bin \ Release文件夹
right click on your mdf file in solution explorer and go to properties > build options => select copy if newer option and also make sure that you are checking correct database file. if you run on debug mode, go to Bin\Debug folder and check the mdf file in there, if you run on release mode you need to check on Bin\Release folder


我们不能说 - 这里有太多的变数。所以你需要做的第一件事就是收集信息。



首先检查一下它是什么:你得到你的MessageBox吗?如果没有,那么你在吞咽的某个地方发生异常。



仔细检查你的数据库:确保它在一个具有读取权限的文件夹中并写信给所有用户。即使您在登录时启动应用程序,SQL也不会使用您的用户ID来访问文件!



然后检查您如何确认任何数据。确保文件是相同的:用C:\ folder \ file.mdf格式的绝对路径替换路径,而不是使用| DataDirectory |并在退出应用程序之前确认已完成更新。然后再次检查数据以确保它仍在那里。



然后再次运行你的应用程序,并检查数据是否仍然在数据库中变化。



什么时候出错?这应该至少给你一个关于发生了什么的线索。
We can't say - there are just too many variables here. So the first thing you need to do is gather information.

Start by checking what it going on: do you get your MessageBox? if not, then you have a exception happening somewhere that you are swallowing.

Check your database carefully: make sure that it is in a folder that has access permissions for read and write to all users. SQL does not use your user id to access files, even if you start your application under your login!

Then check how you are confirming any data. Make absolutely sure that the file is the same one: replace the path with an absolute path of the form C:\folder\file.mdf instead of working with |DataDirectory| and confirm that the updates have been done before you exit your application. Then check the data again to make sure it is still in there.

Then run your app again, and check that the data is still in the DB before you make any changes.

At what point do things go wrong? That should give you at least a clue as to what is happening.


这篇关于插入到mdf数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆