473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parameter date conversion

maheshwag
71 New Member
my code is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. string sql="insert into dummy(date)values(@date)
  3.  
  4. sqlcommand cmd=new sqlcommand(sql,con)
  5. cmd.parameters.Add("@date", SqlDbtype.datetime).values=maskedtextbox1.text;
  6. cmd.ExecuteNonquery();
  7.  
it's throw varchar to date conversion error how to solve it.

my date format is "DD/MM/YYYY"
Sep 2 '10 #1
4 2118
hype261
207 New Member
I believe you are getting an error because you are .text from the maskedtextbox1 is returning a string instead of a date. To convert it you should be able to cast it to a date using the following code example.

Expand|Select|Wrap|Line Numbers
  1. DateTime convertedDate = DateTime.Parse(dateString);
  2.  
Sep 2 '10 #2
maheshwag
71 New Member
that will convert to the date but sir what about format like DD/MM/YYYY. yeah! here user should type date in dd/mm/yyyy format and sql store date in mm/dd/yyyy format that's the problem how to overcome with it. in paramerized query as per my first post.
Sep 3 '10 #3
hype261
207 New Member
I am not big on localization for SQL Server, but I believe there is a way you can change your SQL Server to natively handle dates the way you want to.

You may want to look at this page.

http://msdn.microsoft.com/en-us/libr...81(VS.85).aspx

Or this one

http://msdn.microsoft.com/en-us/libr...(SQL.100).aspx
Sep 3 '10 #4
Plater
7,872 Recognized Expert Expert
DateTime fields are NOT stored as strings in SqlServer. How you want to view them, does not matter to it.
You can use DateTime.TryPar seExact() to supply the input format of "dd/MM/yyyy" and populate a DateTime object that you can supply to the sql parameter.
Sep 3 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2176
by: nimish | last post by:
I have Month, Day and Year fields on my form. When I submit this form I want to create a valid date from all three fields before inserting into MYSQL table. I tried following: $dob=$Month."-".$Day."-".$Year; $dob = strtotime($dob); But it does not update my date field in the table. I am novice in PHP, do you know where i am making a mistake.
5
16080
by: SalimShahzad | last post by:
Dear Respected Gurus, I need a coding assistant converting from gregorian to hijri and vice versa. I have problem with this codes. the problem Gregorian to Hijri gives 100% results. when i enter this to Hijri to gregorian it either do nothing or go to next record on form. well there r two fields on form that r calc afterevents each other...
4
1273
by: Vishal | last post by:
Hello, I am trying to convert a date from a string like this: Dim dtDate As DateTime = Convert.ToDateTime("Sun, 07 Nov 2004 14:05:04 +0200") Response.Write(dtDate.ToString("dd MMM yyyy")) However I am getting the error:
4
1614
by: dhnriverside | last post by:
Hi peeps I have a datepicker control that's providing dates in the format dd/mm/yyyy (UK). I want to convert this to "yyyy-mm-dd" to store as a text field in my database (had lots of problems with date conversions using "proper" data fields). I used to use ASP, and it was easy, using a combination of Left() Mid() and
1
1632
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings set to "en-UK" and date to dd/MM/yyyy. (I'can't change it !)
1
3225
by: vadala | last post by:
The requirement is to send start data and end date from java to UI (.net) for a functionality. We are setting the time in java (1.5) before handing it over to WebService (sending to UI ) in "ASIA/KUALA_LUMPUR" (MYT) TIMEZONE. OS WIN-XP Strangely UI receives a different date. java side UI side
7
3003
by: bruce.dodds | last post by:
Access seems to be handling a date string conversion inconsistently in an append query. The query converts a YYYYMM string into a date, using the following function: CDate(Right(,2) & "/1/" & Left(,4)) I entered the string "200715" in a record to test an error condition.
2
5409
by: p.smachylo | last post by:
Hello, I am relatively new to Microsoft Access and databases in general, and have a problem - one which I think may necessitate some VBA code (or maybe just modification of the criteria section of the query. I have a table with several columns being imported into a query which will eventually be used in a report. One of the fields in the...
2
5138
by: RN1 | last post by:
A TextBox displays the current date (in dd/mm/yyyy format) & time when a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the date into international format so that the remote server doesn't generate any error, this is what I am doing: --------------------------- Dim strSDate As String Dim strSTime As String Dim strStartDT As...
2
2119
by: anderst | last post by:
Hi! I need help with date conversion, I need a perl-script that transform Wed Mar 28 00:00:00 GMT+02:00 2007 to 2007-03-28 I have tried to use perl modules Date::Manip and Date::Calc, but no succes so far. Maybe I am doing it the wrong way.
0
7839
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...
1
7954
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...
0
8215
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...
0
6610
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...
0
5390
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...
0
3836
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1448
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.