I'm using a C# windows form application
Database type is Microsoft® SQL Server® Compact and version is 4.0.8876.1
When I insert data message box pop up "New Record Added" but I check the database no data inserted table is empty
Why is that? Any wrong with my code?
Thank in advance!
This is my code database and application exe in the same directory
int index = cb1.SelectedIndex;
string apPath = Path.GetDirectoryName(Application.ExecutablePath);
SqlCeConnection con = new SqlCeConnection("Data Source=" + app_path + "\\application.sdf;Persist Security Info=False;");
con.Open();
SqlCeCommand cm = new SqlCeCommand("INSERT INTO tbl_user(u_id,u_name,u_scl,u_que) VALUES (@u_id,@u_name, @u_scl, @u_que)", con);
cm.Parameters.AddWithValue("@u_id", 2);
cm.Parameters.AddWithValue("@u_name", txtname.ToString());
cm.Parameters.AddWithValue("@u_scl", txtscl.ToString());
cm.Parameters.AddWithValue("@u_que", index);
try
{
int eff = cm.ExecuteNonQuery();
if (eff == 1)
{
con.Close();
MessageBox.Show("New Record Added " , "Done");
}
else
{
con.Close();
MessageBox.Show("not inserted ", "Error");
}
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.ToString());
}