sqlce 插入有效,但更改不会出现在服务器 Express 中
我第一次编写应用程序组合 sqlce 数据库(VS2008 c#):
SqlCeCommand identChange = con.CreateCommand();
identChange.CommandText = "SET IDENTITY_INSERT contacts ON";
SqlCeCommand cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO contacts (contactID, firstName, cellularNumber) VALUES (1000, @name1 , @number)";
try
{
con.Open();
cmd.Parameters.AddWithValue("@name1", name1);
cmd.Parameters.AddWithValue("@number", number);
identChange.ExecuteNonQuery();
cmd.ExecuteNonQuery();
con.Close();
}
catch (SqlCeException ex)
{
//log ex
}
using (SqlCeCommand com = new SqlCeCommand("SELECT firstName FROM contacts", con))
{
con.Open();
SqlCeDataReader reader = com.ExecuteReader();
while (reader.Read())
{
string name = reader.GetString(0);
Console.WriteLine("there is " + name);
}
con.Close();
}
我的问题是,当我读取表值时,似乎新行插入正确, 但完成后,当我查看服务器资源管理器窗口中的表数据时,新行不存在,
我想知道我缺少什么......
i wrote first time app combine sqlce database(VS2008 c#):
SqlCeCommand identChange = con.CreateCommand();
identChange.CommandText = "SET IDENTITY_INSERT contacts ON";
SqlCeCommand cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO contacts (contactID, firstName, cellularNumber) VALUES (1000, @name1 , @number)";
try
{
con.Open();
cmd.Parameters.AddWithValue("@name1", name1);
cmd.Parameters.AddWithValue("@number", number);
identChange.ExecuteNonQuery();
cmd.ExecuteNonQuery();
con.Close();
}
catch (SqlCeException ex)
{
//log ex
}
using (SqlCeCommand com = new SqlCeCommand("SELECT firstName FROM contacts", con))
{
con.Open();
SqlCeDataReader reader = com.ExecuteReader();
while (reader.Read())
{
string name = reader.GetString(0);
Console.WriteLine("there is " + name);
}
con.Close();
}
my problem is, when i read the table values its seems that the new row inserted properly,
but after it finish, when i look at the table data in the Server Explorer window, the new row doesn't exists
i would like to know what im missing...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是如何打开数据库文件的?
您是否有可能在每次程序启动时创建数据库?
已编辑
您首先在数据库中插入了一些数据。执行程序,插入新数据。但是新数据不会显示在服务器资源管理器中,对吧?
那么,你的新数据是什么时候消失的呢?程序退出后?
再次执行程序时读取到哪些数据?
How did you open the database file?
Is there any chance you created the database every time the program start?
EDITED
You first inserted some data in the database. Execute the program, inserted new data. But new data does not show up in the server explorer, right?
Then, when did your new data is gone? After program exit?
What data read when you execute the program again?