Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 19th, 2007, 2:02 PM   #1
l2u
Newbie
 
Join Date: Mar 2007
Posts: 24
Rep Power: 0 l2u is on a distinguished road
sql query

Hello..

I use a class OleDbCommand

When my program calls cmdUpdateReturn.ExecuteNonQuery(); program crashes.
cmdUpdateReturn is an object of OleDbCommand.

How can I print sql query string before calling ExecuteNonQuery() to debug it?

The error I get is:
System.Data.OleDb.OleDbException: Syntax error in date in query expression 'BookNo LIKE 'B00000000001' AND BarrowerID LIKE '2000-001' AND DateBarrowed =#marec 19, 2007# AND DateDue =#marec 19, 2007#'.
Is it because the date is in wrong format?

It would be really great if someone could help
Im not familiar with C#, been working with it for a few days

Thanks for help
Best regards
l2u is offline   Reply With Quote
Old Mar 19th, 2007, 3:17 PM   #2
Arla
Professional Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 300
Rep Power: 4 Arla is on a distinguished road
I would guess that the date is in the wrong format like you put.

Easiest two ways to test, one is to create the same query in some sort of query browser (dependent on what Database you are using) and see if it works, other is try taking out predicates and see if it works, remove the date predicates and see what happens, if it works you know it's the dates that are causing issue, if not then must be something else that is wrong as well.
Arla is offline   Reply With Quote
Old Mar 19th, 2007, 3:31 PM   #3
milot
Programmer
 
milot's Avatar
 
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0 milot is on a distinguished road
l2u,

Can you post your query?
Then we'll try to fix it, and for error handling try to use try-catch-finally exception handling.
milot is offline   Reply With Quote
Old Mar 23rd, 2007, 4:45 AM   #4
l2u
Newbie
 
Join Date: Mar 2007
Posts: 24
Rep Power: 0 l2u is on a distinguished road
Hey guys

Heres the command being built:

cmdUpdateReturn = new OleDbCommand("UPDATE tblBarrowed SET DateRetured =@getDateRetured, DelayedDays =@getDelayedDays, Fines =@getFines, Notes =@getNotes, Returned =@getReturned, ModifyBy =@getModifyBy, DateModify =@getDateModify WHERE BookNo LIKE '" + sBookID + "' AND BarrowerID LIKE '" + sBarrowerID + "' AND DateBarrowed =#" + sDTBrrwd + "# AND DateDue =#" + sDTDue + "#" ,clsConnections.CN);

The error happens when DateRetured is the same as DateBarrowed.
I have no idea how to solve this..

Thanks for help again
l2u is offline   Reply With Quote
Old Mar 23rd, 2007, 6:47 AM   #5
milot
Programmer
 
milot's Avatar
 
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0 milot is on a distinguished road
CSharp Syntax (Toggle Plain Text)
  1. DateBarrowed =#" + sDTBrrwd + "# AND DateDue =#" + sDTDue + "#"

Which data type are DateBarrowed and DateDue? if they are DateTime why are the "#" in there? And can you post all the snippet for the parametrized queries that you have used. And please use text highlighter (see this link: http://www.programmingforums.org/for...hlighting.html)
milot is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL injection on an insert query. TCStyle Other Web Development Languages 2 Nov 5th, 2006 8:14 PM
Query and List, PhP Main Page Auto Listing of User Actio Stryker PHP 1 Aug 21st, 2006 4:40 PM
C# VS 2005 - SQL Query Parameters to an ODBC DataSource jcrcarmo C# 3 Apr 10th, 2006 4:58 PM
VB.net SQL query load time Driest Visual Basic .NET 4 Feb 17th, 2006 7:02 PM
What means 'Operation must use updateable query' ? jonyzz ASP 6 Sep 22nd, 2005 7:11 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC