Ashfaque Baig

Ashfaque Baig

  • NA
  • 66
  • 2.9k

Sql query not working with MS Access 2007 database

May 10 2020 11:04 AM
Hi Freinds
 
below sql query is working nicely when using sql database but with ms acess database this query show msg "
System.Data.OleDb.OleDbException: 'Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.'"
 
please help me to come out from this issue
  1. private void btnSAVE_Click(object sender, EventArgs e)  
  2. {  
  3. using (OleDbConnection conn = new OleDbConnection(conString))  
  4. {  
  5. conn.Open();  
  6. OleDbCommand cmd = conn.CreateCommand();  
  7. cmd.CommandType = CommandType.Text;  
  8. cmd.CommandText = "IF EXISTS(select * from tblSUPPLIER where SUPPLIERID='" + txtSUPPLIERID.Text + "') update tblSUPPLIER set [SUPPLIERNAME] = '" + txtSUPPLIERNAME.Text + "' where SUPPLIERID = '" + txtSUPPLIERID.Text + "' ELSE insert into tblSUPPLIER (SUPPLIERNAME) values('" + txtSUPPLIERNAME.Text + "')";  
  9. cmd.ExecuteNonQuery();  
  10. conn.Close();  
  11. }  
  12. MessageBox.Show("Added successfully!");  
  13. }  

Answers (1)