Link to home
Start Free TrialLog in
Avatar of Gamecode
GamecodeFlag for Denmark

asked on

ExecuteNonQuery error Missing Parameters

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

ASKER CERTIFIED SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Miguel Oz
Your update statement is incorrect. you are missing the single quotation in your parameters.

See http://www.w3schools.com/SQl/sql_update.asp
Avatar of Gamecode

ASKER

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 :)
Okay I get it, it's because the update statement needs aprostofs, so I need to trick the c# code a little thanx again.
Sorry, the new update string is here:
string SQLUpdateString = String.Format("UPDATE tblKunde SET firmaNavn='{0}' WHERE IdKunde='{1}'", firmanavn, idkunde);