我有一个问题,不能更改提交到SQL Server Compact Edition数据库
private void button_Submit_Click(object sender, EventArgs e)
{
try
{
string connectionString = @"Data Source=Database_TouchPOS.sdf;Persist Security Info=False;";
using (SqlCeConnection connection = new SqlCeConnection(connectionString))
{
using (SqlCeCommand command = connection.CreateCommand())
{
connection.Open();
command.CommandText = "INSERT INTO Product (Title,Price,Category_Id) VALUES (@title, @price,@category_Id)";
command.Parameters.AddWithValue("@title", textBox_Title.Text);
command.Parameters.AddWithValue("@price", textBox_Price.Text);
command.Parameters.AddWithValue("@category_Id", comboBox_Category.SelectedIndex);
command.ExecuteNonQuery();
MessageBox.Show("Product Added Successfully...");
}
connection.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
一切似乎是罚款,但仍无法将数据添加到数据库中。
- 我曾尝试用完整的数据库路径,例如
c:\project\database.sdf
- 我做了很多的搜索要求之前。我看到了类似的问题,但即使一个人也不适合我。
- 数据在编译时添加但未提交到数据库。我可以在第二次尝试调试后看到数据。
- 请详细解释一下。
感谢
using(SqlCeConnection connection = new SqlCeConnection(connectionString))con)) 这里的con是什么? – 62071072SP
这将是我评论删除,修正!,谢谢 –
你的数据库文件位于何处?在bin目录中?检查它是否未被默认文件覆盖并尝试将其放置在其他位置。 – Peter