Windows Develop Bookmark and Share   
 index > Windows Forms General > error occuring in sqlserver sql statement in vb.net
 

error occuring in sqlserver sql statement in vb.net

hi,

I wrote a small program to retrieve the record between two dates from sql server data base but the application giving a system error while i'm using # symbol to delimit the dates.

my sql statement is ;

"select * from table name where date_field between #" & date1 & " #,#" & date2 & "#"

i tried the above with @ symbol also but the same error occuring. when i use this sql statement with the single quotes as the delimiter then it is giving the entire records in the table. the date format i changed to "DD/MM/YYYY" in the regional settings of Indian standard.

Hope i conveyed the question correctly. looking forward for the solution.\

regards

GRK

GRK  Friday, September 08, 2006 2:12 PM

SQL Server doens't use the # syntax like Access. You could replace # with '....I think you'd have to send the SQL in MM/DD/YYYY format though to get this to work.

Dates can be particularly troublesome when firing off SQL like this....you'd be much better off using a stored procedure. Eg;

CREATE PROCEDURE GetDateData

(
@StartDateSMALLDATETIME,
@EndDateSMALLDATETIME
)

AS

SET NOCOUNT ON

/*
__________________________________________________________________________________________
Author:Dylan Morley
Description:

Created:
Modification History:DateModified ByModification
[dd/mm/yy][Name][Desc]

__________________________________________________________________________________________
*/

SELECT
*
FROM
MyTable
WHERE
DateField BETWEEN @StartDate AND @EndDate


SET NOCOUNT OFF

Just call the procedure, passing in your variables.

Dylan Morley  Friday, September 08, 2006 3:55 PM

You can use google to search for other answers

Custom Search

More Threads

• Access Form Instance at runtime
• Multiple Controls. TLayoutPanel
• how can i close privious form
• Will layout change by moving splitter in Splitcontainer ?
• Resize form when Maximized
• Variable Accessing from usercontrol
• How to set proxy?
• Font autoscaling and dynamically created nested user controls
• ComboBox hides mouse cursor when typing in text area.
• Auxiliary control missing in Recording Control