Data isn’t inserted into database from my C# app, but there’s no error or exception found. But I can read the data from database using select statement and data reader.
private void button2_Click(object sender, EventArgs e)
{
string conString = Properties.Settings.Default.dbConnectionString;
// Open the connection using the connection string.
SqlCeConnection con = new SqlCeConnection(conString);
con.Open();
// Insert into the SqlCe table. ExecuteNonQuery is best for inserts.
SqlCeCommand com = new SqlCeCommand("INSERT INTO test VALUES('num')", con);
com.CommandType = CommandType.Text;
// com.Parameters.AddWithValue("@num", "num");
com.ExecuteNonQuery();
MessageBox.Show("ok");
}
After pressing the button the message box shows. But data is not inserted.
Connection string:
Data Source=d:\manu\smalldb\smalldb\db.sdf
Maybe you have to do some commit to validate the transaction
Like HERE
OR
Maybe the problem is in the place where the insertion is done and the place you look after.
Look HERE if it is the case. this article speaks about the “Copy to Output Directory” settings. It can be your problem!