我試圖將任何東西放入我的數據庫。消息框顯示我確實向DB放了1行,但是當我檢查它時 - 什麼也沒有發生。嘗試在數據庫表中插入一行失敗
有人知道治癒嗎?
SqlCeConnection cn = new SqlCeConnection(@"Data Source = Database1.sdf");
try
{
cn.Open();
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.ExitThread();
}
SqlCeCommand cm = new SqlCeCommand("INSERT INTO Sentences (Sentence) VALUES ('Sentence')", cn);
//cm.Parameters.AddWithValue("@Sentence", "Any sentence");
try
{
int rowsAffected = cm.ExecuteNonQuery();
MessageBox.Show((rowsAffected.ToString()));
}
catch (Exception)
{
MessageBox.Show("Insertion Failed");
}
cn.Close();
請勿在標題中使用標籤! –
您是否在任何地方提交交易? http://stackoverflow.com/questions/2912112/c-sharp-rollback-sqltransaction-in-catch-block-problem-with-object-accessabi – rie819
你確定嗎?關閉然後重新打開表格。 –