We help IT Professionals succeed at work.

ExecuteNonQuery error Missing Parameters

376 Views
Last Modified: 2013-12-17
Can somebody tell me why this code is not working? when I get to the line with the ExecuteNonQuery I get an error called "one or more parameters missing".
I use a similar code for both inserting and deleting data and those are working fine.
The code is writen in Microsoft Visual c# express and I am using a access database.


string SQLUpdateString = "UPDATE tblKunde SET firmaNavn=" + firmanavn + " WHERE IdKunde=" + idkunde + "";
            OleDbCommand SQLCommand = new OleDbCommand(SQLUpdateString, f1.database); 
            try
            {
                int response = SQLCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Open in new window

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Miguel OzSenior Software Engineer
CERTIFIED EXPERT
Top Expert 2009

Commented:
Your update statement is incorrect. you are missing the single quotation in your parameters.

See http://www.w3schools.com/SQl/sql_update.asp

Author

Commented:
Thanx that did the trick, I just don't understand why this problem occurs only when updating the database and not when I insert or delete, but thanx for the quick respons :)

Author

Commented:
Okay I get it, it's because the update statement needs aprostofs, so I need to trick the c# code a little thanx again.
Miguel OzSenior Software Engineer
CERTIFIED EXPERT
Top Expert 2009

Commented:
Sorry, the new update string is here:
string SQLUpdateString = String.Format("UPDATE tblKunde SET firmaNavn='{0}' WHERE IdKunde='{1}'", firmanavn, idkunde);


Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.