2016-05-15 23 views
-2

當我嘗試運行並在我的數據庫中插入數據時出現語法錯誤....我有一個登錄按鈕和刪除按鈕,工作正常....但這一個不我不明白.....有人可以告訴我一個替代插入或錯誤是什麼?Acces數據庫應用程序中的斷點C#

public partial class Register : Form 
    { 
     private OleDbConnection connect = new OleDbConnection(); 
     public Register() 
     { 
      InitializeComponent(); 
      connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=resources\Users.accdb; 
Persist Security Info=False;"; 
     } 
    private void register1_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      connect.Open(); 
      OleDbCommand command = new OleDbCommand(); 
      command.Connection = connect; 
      command.CommandText ="insert into Users(Username, Password, Email) values(' " + userR_box.Text + " ',' " + passwordR_box.Text + " ',' " + mailR_box.Text + " ')"; 
          if ((userR_box.Text == "") || (passwordR_box.Text == "") || (mailR_box.Text == "")) 
      { 
       MessageBox.Show("Va rugam completati toate campurile"); 
      } 
      else 
      { 
       command.ExecuteNonQuery(); 

      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Error "+ ex); 
     } 
     connect.Close(); 
    } 
+0

你能添加錯誤跟蹤嗎? –

回答

-1

看你的代碼,我注意到了三兩件事:

  • 你有額外的空間,每個值' " + userR_box.Text + " '
  • 它不清楚是什麼,你正在嘗試插入數據,如果它包含'或之前其他字符可能會影響查詢...這將導致錯誤。
  • 密碼爲保留關鍵字,請使用此INSERT into Users ([Username], [Password], [Email]...以避免保留關鍵字。
相關問題