Hello,
When I try to insert something into my Local Database (SQL Compact) it does add. But it doesn't save. I have tried serveral things. Here is my code:
Connection String
public static SqlCeConnection Connect()
{
SqlCeConnection connection = new SqlCeConnection();
connection.ConnectionString = @"Data Source=|DataDirectory|\Database\Database.sdf";
connection.Open();
return connection;
}
The "Add" Class.
public static void AddTodo(string title, string description, string content)
{
SqlCeCommand command = new SqlCeCommand("insert into items (title, description, content) values (@Title, @Description, @Content)", Database.Connect());
command.Parameters.Add(new SqlCeParameter("Title", title));
command.Parameters.Add(new SqlCeParameter("Description", description));
command.Parameters.Add(new SqlCeParameter("Content", content));
command.ExecuteNonQuery();
Database.Disconnect();
}
Last piece of code
private void addButton_Click(object sender, RoutedEventArgs e)
{
TodoAdder.AddTodo(titleBox.Text, descriptionBox.Text, contentBox.Text);
}
When I rebuild database it deletes it. Or it never is in there.
Thanks in advance.
Updated question:
When I execute the insert query it does show up in the ListBox. But when I check my Database it is empty. Also, when I restart the program. It is empty again.