strange problem could be a bug

T

Tony Johansson

Hello!

Here I have a simple program that just insert a row into a table from a
program.
I use Sql Server CE.
The Database table Movies consist of two columns which are MovieID and Name.
I start by enter a row into this database(sdf file) from Server Explorer in
Visual Studio.
I set MovieID to 1001 and Name to Test1 so this table Movies contains just
one row now.
Now I run the program below in debug mode.
I first check the DataSet ds at position marked with 1 and I can see that
the MovieID is 1001 and name is Test1 so that is correct.

Now I run the program to position marked with 2 and check the DataSet ds and
here it's wrong because I have a duplicate of one row.
Here is how the DataSet look like at position 2
1001 Test1
1001 Test1
1002 Test2

So my first question is why do I have a duplicate ?
My second question is if I now use the Server Explorer is Visual Studio and
look at Database1.sdf it
contains only the first row. the second row that I inserted is not there.
Can somebody explain this ?
1001 Test1


static void Main(string[] args)
{
DataSet ds = new DataSet();
string conStr = @"Data Source=|DataDirectory|\Database1.sdf";
SqlCeConnection con = new SqlCeConnection(conStr);
SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM Movies", con);
SqlCeDataAdapter adapt = new SqlCeDataAdapter(cmd);
1 adapt.Fill(ds, "Movies");

SqlCeCommand myCommand = con.CreateCommand();
string insSql = string.Format("INSERT INTO Movies (MovieID, Name)
VALUES ('{0}', '{1}')", 1001, "Test1");
command.CommandText = insSql ;

con.Open();
command.ExecuteNonQuery();
2 adapt.Fill(ds, "Movies");
}

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top