SQLCE 3.5 - Insert never gets committed (Solved)

Jun 19 2008 12:39 PM

Hello,

 I am trying to insert rows into an existing database using the below logic. I receive no errors, if I do not properly specify a FK it will error, so I am assuming it does the commit. However using server explorer or a datagrid I never see any data. Any help would be greatly appreciated.

try{

conn = new SqlCeConnection(@"Data Source=|DataDirectory|\MediaLister.sdf");

conn.Open();

trans = conn.BeginTransaction();

SqlCeCommand insertMedia = conn.CreateCommand();

String insertMediaSql = "INSERT INTO Media(MediaName, MediaType, MediaLength, MediaDescription)" +

"VALUES ('MediaName', 'DVD', 'MediaLength', 'MediaDescription')";

// "VALUES (@MediaName, @MediaType, @MediaLength, @MediaDescription)";

insertMedia.Transaction = trans;

insertMedia.CommandText = insertMediaSql;

//insertMedia.Parameters.Clear();

//insertMedia.Parameters.AddWithValue("@MediaName", this.MediaNameTB.Text);

//insertMedia.Parameters.AddWithValue("@MediaType", this.MediaTypeDDL.Text);

//insertMedia.Parameters.AddWithValue("@MediaLength", this.MediaLengthTB.Text);

//insertMedia.Parameters.AddWithValue("@MediaDescription", this.MediaDescTB.Text);

insertMedia.ExecuteNonQuery();

trans.Commit(CommitMode.Immediate);

}

catch (SqlCeException ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

}

finally

{

if (conn != null && conn.State == ConnectionState.Open)

{

conn.Close();

}

}


  Many thanks in advance.
 Jeremy


Answers (1)