我有一個問題,不能更改提交到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