using parameters in Access insert query

I have the following code that isn't working right.  Its inserting the text @code instead of the value of codevalue.text.tostring()
OdbcConnection con = new OdbcConnection("DSN=ShipData");
            string sqlQuery = "INSERT INTO Address ([Code],[Company],[Name],[Phone],[Address],[Address2],[City],[State],[ZIP],[Country],[E-mail],[Fdx_accnt]) VALUES"
                            + " ('@code','@company','@contact','@phone','@addy','@addy2','@city','@state','@zip','@country','@email','@fdx_accnt')";
            OdbcCommand dbcommand = new OdbcCommand(sqlQuery, con);
            dbcommand.Parameters.Add("@code", OdbcType.VarChar,40).Value = codevalue.Text.ToString();
            dbcommand.Parameters.Add("@company", OdbcType.VarChar,40).Value = compvalue.Text.ToString();
            dbcommand.Parameters.Add("@contact", OdbcType.VarChar,40).Value = namevalue.Text.ToString();
            dbcommand.Parameters.Add("@phone", OdbcType.VarChar,40).Value = phonevalue.Text.ToString();
            dbcommand.Parameters.Add("@addy", OdbcType.VarChar,40).Value = addy1value.Text.ToString();
            dbcommand.Parameters.Add("@addy2", OdbcType.VarChar,40).Value = addy2value.Text.ToString();
            dbcommand.Parameters.Add("@city", OdbcType.VarChar,40).Value = cityvalue.Text.ToString();
            dbcommand.Parameters.Add("@state", OdbcType.VarChar,40).Value = statesdropdown.Text.ToString();
            dbcommand.Parameters.Add("@zip", OdbcType.VarChar,40).Value = zipvalue.Text.ToString();
            dbcommand.Parameters.Add("@country", OdbcType.VarChar,40).Value = countryvalue.Text.ToString();
            dbcommand.Parameters.Add("@email", OdbcType.VarChar,40).Value = emailvalue.Text.ToString();
            dbcommand.Parameters.Add("@fdx_accnt", OdbcType.VarChar,9).Value = fdx_accntvalue.Text.ToString();
            con.Open();
            try
            {
                int count = dbcommand.ExecuteNonQuery();
            }
            catch (OdbcException ex)
            {
                MessageBox.Show(ex.Message);
            }

Open in new window

casitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

drichardsCommented:
I don't think you have the parameter syntax correct in your query.  I believe you do not use quotes around the parameter names.
            string sqlQuery = "INSERT INTO Address ([Code],[Company],[Name],[Phone],[Address],[Address2],[City],[State],[ZIP],[Country],[E-mail],[Fdx_accnt]) VALUES"
         + " (@code,@company,@contact,@phone,@addy,@addy2,@city,@state,@zip,@country,@email,@fdx_accnt)";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
casitAuthor Commented:
Now its telling me 12 parameters are expected.
0
drichardsCommented:
So the syntax of the query is correct, and I don't see anything else blatantly incorrect.  I assume you validated that the command parameter collection has 12 items prior to ExecuteNonQuery?
0
casitAuthor Commented:
Yeah.  I even debugged it and then looked at the output of the paramters to make sure they had values and they did.  so I just put the variables right into the sql query.  Will have to figure it out later.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.