Menu
Home
Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Database
SQL Server
DateTimePicker syntax error
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Moordoom" data-source="post: 164573" data-attributes="member: 48852"><p>I am trying to do an SQL Select Query by using the dates supplied by two DateTimePickers to export data from a SQL Server to an Excel Spreadsheet.</p><p>When I run the app, I get "Line1: Incorrect syntax near 'Tuesday, November 12, 2013 AND Wednesday, November 13, 2013'. "</p><p></p><p>The query is being run on an SQL 2000 server, and the DateTime Format on the server is MM/dd/yyyy hh:mm:ss tt in the record.</p><p></p><p>I have tried doing a DateTimePickerFormat</p><p>[CODE] </p><p>DateTimePicker1.Format = DateTimePickerFormat.Custom</p><p>DateTimePicker1.CustomFormat = "MM/d/yyyy hh:mm:ss tt"</p><p>DateTimePicker2.Format = DateTimePickerFormat.Custom</p><p>DateTimePicker2.CustomFormat = "MM/d/yyyy hh:mm:ss tt"</p><p>[/CODE]</p><p></p><p>Which gives the same error in 11/12/2013 02:00:00 PM 11/13/2013 02:00:00 PM</p><p></p><p>I have Tried</p><p>[CODE]</p><p>DatePicker1.Format = DateTimePickerFormat.Custom</p><p>DateTimePicker1.CustomFormat = "MM/d/yyyy"</p><p>DateTimePicker2.Format = DateTimePickerFormat.Custom</p><p>DateTimePicker2.CustomFormat = "MM/d/yyyy"</p><p>[/CODE]</p><p></p><p>Which gives the same error in 11/12/2013 AND 11/13/2013</p><p></p><p>Here is my current Select code...</p><p></p><p>[CODE]</p><p>Dim dataAdapter As New SqlClient.SqlDataAdapter()</p><p>Dim dataSet As New DataSet</p><p>Dim command As New SqlClient.SqlCommand</p><p>Dim datatableMain As New System.Data.DataTable()</p><p>Dim connection As New SqlClient.SqlConnection</p><p></p><p>DateTimePicker1.Format = DateTimePickerFormat.Custom</p><p>DateTimePicker1.CustomFormat = "MM/d/yyyy"</p><p>DateTimePicker2.Format = DateTimePickerFormat.Custom</p><p>DateTimePicker2.CustomFormat = "MM/d/yyyy"</p><p></p><p>Dim dt1 As String = DateTimePicker1.Text</p><p>Dim dt2 As String = DateTimePicker2.Text</p><p></p><p>connection.ConnectionString = "Data Source=SQL01_2000;database=App_DB;uid=sa;pwd=sa"</p><p>command.Connection = connection</p><p>command.CommandType = CommandType.Text</p><p>command.CommandText = "Select * from LabelCheck WHERE [Date1] BETWEEN '" & dt1 & " AND " & dt2 & "'"</p><p>dataAdapter.SelectCommand = command</p><p>[/CODE]</p><p></p><p>What am I missing?</p><p>I put this in the Forms Forum, but it may belong in the SQL one.</p></blockquote><p></p>
[QUOTE="Moordoom, post: 164573, member: 48852"] I am trying to do an SQL Select Query by using the dates supplied by two DateTimePickers to export data from a SQL Server to an Excel Spreadsheet. When I run the app, I get "Line1: Incorrect syntax near 'Tuesday, November 12, 2013 AND Wednesday, November 13, 2013'. " The query is being run on an SQL 2000 server, and the DateTime Format on the server is MM/dd/yyyy hh:mm:ss tt in the record. I have tried doing a DateTimePickerFormat [CODE] DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "MM/d/yyyy hh:mm:ss tt" DateTimePicker2.Format = DateTimePickerFormat.Custom DateTimePicker2.CustomFormat = "MM/d/yyyy hh:mm:ss tt" [/CODE] Which gives the same error in 11/12/2013 02:00:00 PM 11/13/2013 02:00:00 PM I have Tried [CODE] DatePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "MM/d/yyyy" DateTimePicker2.Format = DateTimePickerFormat.Custom DateTimePicker2.CustomFormat = "MM/d/yyyy" [/CODE] Which gives the same error in 11/12/2013 AND 11/13/2013 Here is my current Select code... [CODE] Dim dataAdapter As New SqlClient.SqlDataAdapter() Dim dataSet As New DataSet Dim command As New SqlClient.SqlCommand Dim datatableMain As New System.Data.DataTable() Dim connection As New SqlClient.SqlConnection DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "MM/d/yyyy" DateTimePicker2.Format = DateTimePickerFormat.Custom DateTimePicker2.CustomFormat = "MM/d/yyyy" Dim dt1 As String = DateTimePicker1.Text Dim dt2 As String = DateTimePicker2.Text connection.ConnectionString = "Data Source=SQL01_2000;database=App_DB;uid=sa;pwd=sa" command.Connection = connection command.CommandType = CommandType.Text command.CommandText = "Select * from LabelCheck WHERE [Date1] BETWEEN '" & dt1 & " AND " & dt2 & "'" dataAdapter.SelectCommand = command [/CODE] What am I missing? I put this in the Forms Forum, but it may belong in the SQL one. [/QUOTE]
Insert quotes…
Verification
Post reply
Home
Forums
Database
SQL Server
DateTimePicker syntax error
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom