I'm trying to write a simple insert statement for a SQL Server CE database, and my code works perfectly! ...except that the row doesn't actually get inserted into the database...
My code is:
public static int InsertTourCreater(string userName, string password)
{
SqlCeConnection connection = GuidedTourDB.GetConnection(); //Returns connection
string insertStatement =
"INSERT INTO [Tb_Creater] " +
"([User_Name], [Password]) " +
"VALUES (@UserName, @Password)" ;
SqlCeCommand insertCommand = new SqlCeCommand(insertStatement, connection);
insertCommand.Parameters.Add(new SqlCeParameter("@UserName", SqlDbType.NVarChar)).Value = userName;
insertCommand.Parameters.Add(new SqlCeParameter("@Password", SqlDbType.NVarChar)).Value = password;
try
{
connection.Open();
int success = insertCommand.ExecuteNonQuery();
return success;
}
Code runs fine. Stepping through in debug mode, the connection opens, the values all get added correctly, and the ExecuteNonQuery()
returns value of 1, but then I go to look at table data in Tb_Creater
in my Server Explorer, and the record isn't there.
I've refreshed and even restarted visual studio. Not there. No exceptions are thrown.
Note: I'm adding parameters like that instead of AddWithValue()
because I was worried that the strings would convert to varchar
(which isn't available in SQL Server CE) by default, and cause problems, however the code operates the same either way.