簡體   English   中英

oleDB插入新條目

[英]oleDB inserting new entry

我是使用Microsoft Access創建數據庫的。 我只能從該數據庫中讀取數據,而不能向其中添加新條目,

我使用下面的代碼插入數據

cmd = new OleDbCommand("insert into [Accountstbl] values(" + textBox1.Text + 
",' " + textBox6.Text + " ',' " + textBox3.Text + " ')", cn);

但是,當我單擊“確定”時,表單變成沒有響應並且沒有在數據庫中插入任何數據,我知道我的路徑是正確的,因為我可以讀取數據,

你能給我一個指導嗎? 找不到任何東西:(謝謝,

缺少第一個文本框(textBox1.Text)的單引號?

嘗試以下之一

cmd = new OleDbCommand("insert into [Accountstbl] values('" + textBox1.Text + 
"',' " + textBox6.Text + " ',' " + textBox3.Text + " ')", cn);

並嘗試將以下代碼放在您懷疑它出問題的地方

try
{
   //Insertion code here, .............Query,ExcuteNonQuery,.....etc
} 
catch(Exception ex)
{
  MessageBox.Show(ex.ToString());//You will get here what problem is there.....
}

嘗試:

cmd = new OleDbCommand("insert into [Accountstbl] (field1, field2, field3) values(" + textBox1.Text + ",' " + textBox6.Text + " ',' " + textBox3.Text + " ')", cn);

用數據庫中的字段替換field#。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM