473,748 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date convertion problem

Hi,
i am having a hard time trying to convert my date. Here is my problem :

I get an input date from a user in a form (in a asp:textbox control). The
date is validated with the "dd/MM/yyyy" format and stored in a variable.

Dim strDate As DateTime = Date.Text (strDate contains:20/10/2004 00:00:00)
Or
Dim strDate As String = Date.Text (strDate contains:20/10/2004)

If i want to insert my strDate value in it's field in my SQL Server 2000
database, then i can't because the date field (datetime type) is in a
"MM/dd/yyyy" format.

Is there a way/function/method that can convert this date. For example,
ToShortDateStri ng() on my variable would work if my CurrentCulture would
NOT be "en-GB" but it is...

The way i thought was to convert my variable just before inserting in my
database by using the CONVERT function in my SQL statement but i am not
sure if it is the right thing to do. I even tryed it and it failed :

Dim cmd As New SqlCommand ("INSERT INTO MYTABLE (Date)VALUES('C ONVERT
(DATETIME," & strDate & ",101)')", MyConnection)

My Error message:
System.Data.Sql Client.SqlExcep tion: Syntax error converting datetime from
character string.

What i am doing wrong?
Isn't there any other way to do such a thing (e.g. change the Culture just
the time to insert the record)?

Any help is greatly appreciated.

Jonathan
Jul 21 '05 #1
1 1645
Jonathan <aa*@aaa.com> wrote:
i am having a hard time trying to convert my date. Here is my problem :

I get an input date from a user in a form (in a asp:textbox control). The
date is validated with the "dd/MM/yyyy" format and stored in a variable.

Dim strDate As DateTime = Date.Text (strDate contains:20/10/2004 00:00:00)
Or
Dim strDate As String = Date.Text (strDate contains:20/10/2004)

If i want to insert my strDate value in it's field in my SQL Server 2000
database, then i can't because the date field (datetime type) is in a
"MM/dd/yyyy" format.


Don't include the string format of the date into your SQL statement at
all. Use database parameters instead.

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
558
by: F | last post by:
Hi I have one field in SQL Database datatype as datetime. When I am inserting or updating using asp on my machine its working fine but when I installed DB and application on other server and try to insert or update date using asp it giving error of date convertion. I know that its date format problem on one server it accept only "24/07/2004" format but on second server it accept as "07/24/2004" .
6
2239
by: Chiller | last post by:
I'm in the process of writing a class that performs functions on a Distance object. The object is created by entering details as "Distance a (5, km)" or "Distance b (3, cm)" etc. I wish to write a function that I can call to "as required by comparison functions" to convert any value to a mm value so that when I'm comparing Distance objects the values will all be the same. The code I've come up with is below; however, it doesn't work...
3
14610
by: andrew | last post by:
Hi: I am already using TreeMap to massage records in my export file such that each record has a unique key combination ( LastName + FirstName + Member Key) . Thus I am sorting the records by the unique key. I also have a Date String Field in my record ( ie "30-Apr-2005" ). I want to create a unique key combination of ( LastName + FirstName + Member Key + Date). Can you please tell me what are the steps I need to do to sort the Date
1
1631
by: Vidar | last post by:
I have a problem in dotNET XSL convertion object. (XMLTRANSFORM) It won't convert UTF-8 to ISO-8859-1 I use this stylesheet for konvertion: <?xml version="1.0" encoding="ISO-8859-1"?> <!-- For convertion from UTF-8 to ISO-8859-1 CaracterSet --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
0
324
by: McKoy | last post by:
Hi, I'm translating some code from C++ to C#, but I don't know how to change the code below to get it working under C# ...., I've tried explicity convertion, but without any results :( Please help.... int b = -1; uint a,c = 0; Encoding encodingAscii = Encoding.GetEncoding(1250);
1
241
by: Jonathan | last post by:
Hi, i am having a hard time trying to convert my date. Here is my problem : I get an input date from a user in a form (in a asp:textbox control). The date is validated with the "dd/MM/yyyy" format and stored in a variable. Dim strDate As DateTime = Date.Text (strDate contains:20/10/2004 00:00:00) Or Dim strDate As String = Date.Text (strDate contains:20/10/2004)
9
12945
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i convert textbox data into Datatime formate it converted into MM/dd/yyyy formate, but i have a requirement in dd/MM/yyyy formate. please help me, i am using c#.
3
3442
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the current date and time expressed in minutes? Once I have this number I can add the number of minutes purchased to the current date/time to get the expiration date.
4
2776
by: HackerisNewKnight | last post by:
Hello, 1) First problem. In my project i need to convert from char* to BYTE*( BYTE is unsigned char), is there any way to make the convertion? BYTE* bite; char* ch="help me, please"; bite = (BYTE*)ch; ? is this not right? what shoul i do here?
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8235
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.