4 Replies - 2252 Views - Last Post: 12 January 2010 - 12:59 PM Rate Topic: -----

#1 dgutie01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 10

Trouble with a local MS SQL Compact DB

Posted 12 January 2010 - 08:56 AM

Hey guys, I'm attempting to connect to, and add information to a local MS SQL Compact .sdf file in c#. I'm definitely able to connect to the database with no issues, I know this because I can run SELECT queries on it successfully. But I can not seem to run any INSERT queries, I do not receive any errors or warnings when trying to, just nothing happens to the database when I check its contents.

Here is the code..

		   SqlCeConnection connection = new SqlCeConnection(Properties.Settings.Default.Database1ConnectionString.ToString());
		   
			connection.Open();
			
			SqlCeCommand command = new SqlCeCommand("INSERT INTO Songs (Title_E, Title_S) VALUES('Test2', 'Test2')", connection);
		   
			if (connection.State != ConnectionState.Open)
				return;
			MessageBox.Show("Executing");

			command.ExecuteNonQuery();
			

			connection.Close();





I've also tried using data adapters..
			SqlCeConnection connection = new SqlCeConnection(Properties.Settings.Default.Database1ConnectionString.ToString());
			connection.Open();
			
			SqlCeCommand command = new SqlCeCommand("SELECT * From Songs",connection);
			if (connection.State != ConnectionState.Open)
				return;

			MessageBox.Show("Executing");
			SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(command);

			DataSet data = new DataSet();
			dataAdapter.Fill(data);

		   data.Tables[0].Rows.Add(new object[] { null, "Test", "Probando", "Major", "Jubilo", "ES", "v1", "v2", "v3", "v4", "v1", "v2", "v3", "v4", "c1", "c1" });
			data.Tables[0].AcceptChanges();
			dataAdapter.Update(data);			

			connection.Close();




Both these snippets of code run successfully with no errors, warnings, exceptions, assertions, ect. Can anyone point me in the right direction as to why my database doesn't get updated with the new row?

Is This A Good Question/Topic? 0
  • +

Replies To: Trouble with a local MS SQL Compact DB

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Trouble with a local MS SQL Compact DB

Posted 12 January 2010 - 09:01 AM

.

This post has been edited by FlashM: 12 January 2010 - 09:02 AM

Was This Post Helpful? 0
  • +
  • -

#3 dgutie01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 10

Re: Trouble with a local MS SQL Compact DB

Posted 12 January 2010 - 09:44 AM

Is that supposed to be my answer? =)
Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Trouble with a local MS SQL Compact DB

Posted 12 January 2010 - 11:37 AM

I overlooked some lines of code you posted, so my answer wouldn't resolve anything and since it is not possible to delete a post, I just replaced my text with period. Sorry :-)
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Trouble with a local MS SQL Compact DB

Posted 12 January 2010 - 12:59 PM

do you get a message box saying "executing" when using the first code snippet?

Would you mind posting your connection string?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1