?
Solved

Problem with oleDB Command Text

Posted on 2009-04-16
3
Medium Priority
?
230 Views
Last Modified: 2012-05-06
Whats wrong with this?

OleDbCommand cmd = mycon.CreateCommand();
            sMatchID = "test";
            sTime = "0001";
            sEvent = "TB";
            sPlayerNo = "11";
            sPlayerName = "Harry";
 cmd.CommandText = "insert into MatchStats values(" + sMatchID + ",'" + sTime + ",'" + sEvent + ",'" + sPlayerNo + ",'" + sPlayerName + "');";

I have an access database with a table called MatchStats with the above columns.

WHen the debugger comes to this line:
int temp = cmd.ExecuteNonQuery();
 I get an exception saying:
OleDBException was unhandled
Syntax error (missing operator) in query expression '0001',TB'.

Whats wrong?
0
Comment
Question by:Wanting2LearnMan
  • 2
3 Comments
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 999 total points
ID: 24158722
I think if you output your command, you will see a quote mismatch.

msgbox "insert into MatchStats values("   sMatchID   ",'"   sTime   ",'"   sEvent   ",'"   sPlayerNo   ",'"   sPlayerName   "');";

Above I can see that 0001 (sTime) and TB (sEvent) appear to have a missing quote based on your output.
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 501 total points
ID: 24159161
Brandon has identified the problem, its to do with quotes but for any numeric valus eg player no? ensure there are no quotes
0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 999 total points
ID: 24159357
I would not assume that player no is a number field.  the potential for player "07" would make it a varchar at least.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question