SQL精简版将C# [英] SQL Compact Edition Insert C#
问题描述
我想一些值插入到SQL CE数据库这样并没有任何反应。 ?我做错了。
字符串创建失败= Properties.Settings.Default.SqlConnectionString;
使用(CON的SqlCeConnection =新的SqlCeConnection(创建失败))
{
con.Open();
使用(SqlCeCommand CMD =新SqlCeCommand(插入CustTable表(ID,姓名)值(@ VAL1,@将val2),CON))
{
cmd.Parameters.AddWithValue( @ VAL1,customer.ID);
cmd.Parameters.AddWithValue(@值2,customer.Name);
cmd.CommandType = System.Data.CommandType.Text;
cmd.ExecuteNonQuery();
}
}
如何你要插入一些值...?您是否在运行从Visual Studio应用程序?为什么你认为什么也没发生? ?你运行你的应用程序打开后,原来的.sdf文件
检查Solution Explorer中的数据库文件复制文件属性;它是复制?这意味着,Visual Studio将在你的bin文件夹中创建原始数据库文件的副本,并设置连接字符串到该路径。所有的变化发生在副本,如果检查原始文件将保持不变。
I am trying to insert some values into a SQL CE database like this and nothing happens. What I do wrong?
string strConn = Properties.Settings.Default.SqlConnectionString;
using (SqlCeConnection con = new SqlCeConnection(strConn))
{
con.Open();
using (SqlCeCommand cmd = new SqlCeCommand("insert into CustTable(ID, Name) values (@Val1, @val2)", con))
{
cmd.Parameters.AddWithValue("@Val1", customer.ID);
cmd.Parameters.AddWithValue("@Val2", customer.Name);
cmd.CommandType = System.Data.CommandType.Text;
cmd.ExecuteNonQuery();
}
}
How are you "trying to insert some values..."? Are you running the app from Visual Studio? Why do you think "nothing happens"? Are you opening your original .sdf file after running your app?
Examine the Copy File property for the database file in Solution Explorer; is it "Copy"? That means Visual Studio will create a copy of the original database file in your bin folder and set the connection string to that path. All changes happen to the copy, and if you examine the original file it will be unchanged.
There is another SO question with the same problem; see if that helps.
这篇关于SQL精简版将C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!