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.
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.
My code is as follows:
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();
}
}
}
}
I have a database named test.sdf. It contains a table "test" with 1 column "test".
My sample test app is available at: http://dl.dropbox.com/u/3051071/ConsoleApplication1.zip
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?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…