Reputation: 274
am scratching my head from couple of days, not being able to find what I did wrong. I have a database "compinfo.sdf" and table "cname" in local database.Dataset as "compinfoDataset".I am using this code to insert the data.
static class sqlFunction
{
static public void insert(String _compName)
{
static private SqlCeConnection connection =
new SqlCeConnection(@"Data Source=|DataDirectory|\compinfo.sdf");
try
{
connection.Open();
SqlCeCommand commandInsert = new SqlCeCommand("INSERT into [cname] VALUES (@companyName)", connection);
commandInsert.Parameters.AddWithValue("@companyName", _compName);
int result = commandInsert.ExecuteNonQuery();
MessageBox.Show(result.ToString());
}
catch (SqlCeException exception)
{
MessageBox.Show(exception.ToString());
}
finally
{
connection.Close();
}
}
}
From another class I am sending data as :
sqlfunction.insert(companyName);
So when this code is executed, I get the result of execution as 1 (in message box). But when I check the data in database table, its again nothing there. Please help me find the error.
Upvotes: 0
Views: 1953
Reputation: 13960
Most likely Visual Studio is set to always copy the sdf
file to the bin directory, overwriting any previous changes. Change the behavior to "Do not copy", as explained in this article.
Upvotes: 1