views:

53

answers:

1

Hello,

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.

+2  A: 

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.

Will A
+1 The code seems fine!! I also think that you might be inserting / checking two different databases!!
InSane
I am such a n00b. Thanks so much guys. I was checking the database in my root directory; not my debug directory.
fraXis