为什么我不能插入记录我的SQL Compact 3.5数据库? [英] Why can't I insert a record into my SQL Compact 3.5 database?
问题描述
我只是做了使用文档从MSDN一个非常简单的测试应用程序。所有我想要做的就是记录插入我的表是在我的VS 2010的应用程序在SQL Server Compact数据库。
I just made a very simple test app using documentation from MSDN. All I want to do is insert a record into my table which is in a SQL Server Compact database in my VS 2010 app.
但是,当我运行它,它就像它执行罚款(没有错误),但创纪录的永远不会插入我的SQL Compact 3.5数据库时,我去查看从服务器资源管理器表中的数据。
But when I run it, it acts like it executes fine (no errors), but a record is never inserted into my SQL Compact 3.5 database when I go to view the table data from Server Explorer.
我的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlCeConnection conn = null;
try
{
conn = new SqlCeConnection("Data Source = test.sdf; Password ='pass'");
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO TEST ([test]) Values('NWIND')";
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
}
}
}
我有一个名为test.sdf数据库。它包含一个表测试1列测试
I have a database named test.sdf. It contains a table "test" with 1 column "test".
我的样本测试应用程序,请访问: http://dl.dropbox.com/u/3051071/ConsoleApplication1.zip
My sample test app is available at: http://dl.dropbox.com/u/3051071/ConsoleApplication1.zip
我已经测试数据库连接到我的test.sdf数据库和测试罚款。
I have tested the database connection to my test.sdf database and that tests fine.
我不为我的生活,为什么我不能插入录制到我的表。每当我看到执行后,我的数据,该值始终在我的桌子空。
I can not figure for the life of my why I am unable to insert a record into my table. Whenever I view my data after execution, the value is always null in my table.
有人可以告诉我什么,我做错了什么?
Can someone please tell me what I am doing wrong here?
感谢。
推荐答案
这.sdf文件你在SSMS查看?我只是想你的应用程序 - 检查在bin\Debug文件夹中。自卫队测试表的内容 - 它看起来我的权利
Which .sdf file are you viewing in SSMS? I've just tried your app - check the content of the test table in the .sdf in the bin\Debug folder - it looks right to me.
这篇关于为什么我不能插入记录我的SQL Compact 3.5数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!