473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

parameter date conversion

maheshwag
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

✓ answered by hype261

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

4 2098
hype261
207 100+
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
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 100+
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 Expert 4TB
DateTime fields are NOT stored as strings in SqlServer. How you want to view them, does not matter to it.
You can use DateTime.TryParseExact() 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
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:...
5
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...
4
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")) ...
4
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...
1
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...
1
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...
7
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/" &...
2
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...
2
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...
2
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.