Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Syntax error converting datetime from character String..

Posted on 2006-05-29
9
Medium Priority
?
1,499 Views
Last Modified: 2007-12-19
My program will update my database fields uploaded date using today() function and value will  be

Uploadeddate
5/25/2006 5.51.55  
5/26/2006 4.15.35


My webpage got a text box(txtDate) for the user to keyin the date so i need check the txtDate.txt with my datebase field uploadeddate..

I have written the below query for the above part while configuring my dataadapter.

Select serialno, Uploadedtime from ipssource
where serialno='txtSerial.text' and  
convert(datetime,convert(varchar(10),Uploadedtime,103),103) = convert(datetime,convert(varchar(10),'txtDate.text',103),103.

When i fill the dataset i have got the below error message ..

"SqlDataAdaptor1. The data adaptor could not return the data from the data source

Syntax error converting datetime from character String.."

0
Comment
Question by:nyee84
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 44

Assisted Solution

by:bruintje
bruintje earned 400 total points
ID: 16787306
Hi nyee84,
----------

you could try something like

' be sure to do some validation checks on your textboxes first
' i used OleDb adapter as sample but you replace it for Sql

Public objUploadDA As New OleDb.OleDbDataAdapter("SELECT serialno, Uploadedtime FROM ipssource " & _
        " where serialno='" & txtSerial.text & "' AND " & _
        " convert(datetime,convert(varchar(10),Uploadedtime,103),103) = " & _
        " convert(datetime,convert(varchar(10),'" & txtDate.text & "',103),103) "

----------
bruintje
share what you know, learn what you don't
0
 
LVL 11

Accepted Solution

by:
anyoneis earned 800 total points
ID: 16787557
Get rid of the quotes around txtDate.Text.


Also, rather than doing a double data conversion, consider this:

convert(varchar(10),Uploadedtime,103)= convert(varchar(10),'txtDate.text',103)


David
0
 
LVL 44

Expert Comment

by:bruintje
ID: 16787617
i didn't know that syntax
convert(varchar(10),Uploadedtime,103)= convert(varchar(10),'txtDate.text',103)

passing the box into the query directly is that new?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 16788843
No, that isn't new, that is a problem.  You can't convert the string 'txtDate.Text' to a date.

String.Format("convert(varchar(10),Uploadedtime,103)= convert(varchar(10),'{0}',103)", txtDate.text)

Bob
0
 
LVL 44

Expert Comment

by:bruintje
ID: 16788927
thanks Bob, i'm working mostly in VB or C# windows stuff
so there is always something in ASP.NET i could miss especially since there are 2 comments working with the same syntax
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16789258
No problem, Brian. ;)

Bob
0
 
LVL 2

Assisted Solution

by:zubin_kharas
zubin_kharas earned 400 total points
ID: 16789476
HI there,
 I thought ASP.NET supports the dateTimePicker Control which comes in VB.NET
If you'd use that, users wouldnt need to submit a string plus they wont have to type a date in a specific format, the dateTime Picker is a great easy control to work with. It alqways returns a date type value which you can cstring if needed.
Cheers! Zubin
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16791361
>Get rid of the quotes around txtDate.Text.
>Also, rather than doing a double data conversion, consider this:
>convert(varchar(10),Uploadedtime,103)= convert(varchar(10),'txtDate.text',103)

Arghh... "Get rid of the quotes around txtDate.Text."

I was assuming that txtDate was a table and the column was text, but probably that is not what was intended.


David
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16791514
Another question where the experts talk to each other ;)

Bob
0

Featured Post

Independent Software Vendors: 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

577 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