插入本地数据库C# [英] Insert Into local database C#
本文介绍了插入本地数据库C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在C#中插入并从本地数据库数据中选择.
I can't Insert and select from Local database data in C#.
我已经阅读了这些文章
- C#-在本地数据库中写入数据
- http://msdn.microsoft.com/zh-CN/library/system.data.sqlserverce.sqlceconnection(v=vs.100).aspx
- 如何添加使用C#中的listBox将本地数据库项放入textBox中
所有代码示例都是相同的,这是我的示例.
All the code samples are the same, here's my sample.
SqlCeConnection conn = new SqlCeConnection(@"Data Source=|DataDirectory|\PacjenciDB.sdf");
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText="INSERT INTO pacjenci (nazwiskoimie,adres,skierowany,opis) values (@nazwiskoimie,@adres,@skierowany,@opis)";
cmd.Parameters.AddWithValue("@nazwiskoimie", txtnazwiskoimie.Text);
cmd.Parameters.AddWithValue("@adres", txtadres.Text);
cmd.Parameters.AddWithValue("@skierowany", txtskierowany.Text);
cmd.Parameters.AddWithValue("@opis", txtopis.Text);
cmd.ExecuteNonQuery();
conn.Close();
有人可以告诉我我在做什么错吗?
Can someone tell me what I'm doing wrong?
我已经尝试了很多有关插入数据的示例,但这是行不通的.
I've tried tons of samples about insert data, but it doesn't work.
我可以管理 .MDF
,但是 .SDF
似乎很麻烦.
I can manage .MDF
, but .SDF
seems quite problematic.
希望你能帮助我
推荐答案
在bin/debug文件夹中查找包含数据的数据库副本.
Look for a copy of the database with data in your bin/debug folder.
解决方案是不使用| DataDirectory |,而是使用完整路径.
Solution is to not use |DataDirectory|, but use full path instead.
这篇关于插入本地数据库C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文