By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

Few syntax questions

P: n/a
Hi, to be use with SQL server database

1- From window form textbox object

From this assignement,
txtTOTAL.Text="0.00m";
How do you convert back to decimal type ?

How do you assign a default datetime value to it ? How do
you convert back the text enter by user into datetime ?

txtDATEFAC.Text=DateTime.Now.ToLongTimeString();
give the error Cannot convert type 'string'
to 'System.DateTime'

Carl,

Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I find it,

For decimal,

Convert.ToDecimal(txtTOTAL.Text)

For datetime,

Convert.ToDateTime(txtDATEFAC.Text)

Carl,

-----Original Message-----
Hi, to be use with SQL server database

1- From window form textbox object

From this assignement,
txtTOTAL.Text="0.00m";
How do you convert back to decimal type ?

How do you assign a default datetime value to it ? How doyou convert back the text enter by user into datetime ?

txtDATEFAC.Text=DateTime.Now.ToLongTimeString() ;
give the error Cannot convert type 'string'
to 'System.DateTime'

Carl,

.

Nov 15 '05 #2

P: n/a
I do have one textbox in a windows form.

I can assign the current datetime with out issue with the
following line,

txtDATEFAC.Text=DateTime.Now.ToString();

However, I am not able to save this value from the
textbox in variable of datetime type to be use in SQL
server.

I try the following,
Convert.ToDateTime(txtDATEFAC.Text), it convert to
{9/5/2003} (from the debuger.)

How do we convert to datetime like it was display in the
textbox (05/09/2003 9:56:12 PM
) from DateTime.Now.ToString(); or in a way SQL server
will recognize.

Thanks in advance..

Carl,

Nov 15 '05 #3

P: n/a

Hi Carl,

I think the internal storage of DateTime will become the same, but you can
display the DateTime object
in different format.
For more information, you can visit the link below:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemGlobalizationDateTimeFormatInfoClassTop ic.asp

It provides you much information of formatting the DateTime object.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Carl" <Ca**@cb-cinc.com>
| Sender: "Carl" <Ca**@cb-cinc.com>
| References: <29****************************@phx.gbl>
<32****************************@phx.gbl>
| Subject: DateTime question
| Date: Fri, 5 Sep 2003 19:01:37 -0700
| Lines: 24
| Message-ID: <26****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN0Gs5rXd9kxnEMRAu1G1IeqY2/Vw==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:182783
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I do have one textbox in a windows form.
|
| I can assign the current datetime with out issue with the
| following line,
|
| txtDATEFAC.Text=DateTime.Now.ToString();
|
| However, I am not able to save this value from the
| textbox in variable of datetime type to be use in SQL
| server.
|
| I try the following,
| Convert.ToDateTime(txtDATEFAC.Text), it convert to
| {9/5/2003} (from the debuger.)
|
| How do we convert to datetime like it was display in the
| textbox (05/09/2003 9:56:12 PM
| ) from DateTime.Now.ToString(); or in a way SQL server
| will recognize.
|
| Thanks in advance..
|
| Carl,
|
|

Nov 15 '05 #4

P: n/a
Do you mean the debugger, only display the date without
the time because of is internal display format and in
fact it does have the time but it is only not display??

Following the reading of the link you send me, which
format should be use to be the most standard in Canada
and compatible with SQL server datetime field type?

Also I read some where that SQL server will accept the
datetime string directly in a datetime field type, is
that true ?

However, I still unable from the textbox field (datetime
string) to add record in SQL, I always receive one error
related to field type. I will do more tests tonight on
this, and will try to see if it is not another field
causing this error. I will post back here tomorrow.

Thanks in advance.

Carl,

Nov 15 '05 #5

P: n/a

Hi Carl,

My reply in the line below:

--------------------
| Content-Class: urn:content-classes:message
| From: "Carl" <ca**@cb-cinc.com>
| Sender: "Carl" <ca**@cb-cinc.com>
| References: <29****************************@phx.gbl>
<32****************************@phx.gbl>
<26****************************@phx.gbl>
<R$**************@cpmsftngxa06.phx.gbl>
| Subject: RE: DateTime question
| Date: Mon, 8 Sep 2003 11:43:52 -0700
| Lines: 23
| Message-ID: <3d****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN2OSZFy+I9EqXIS+uL4nwIYM3EEw==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183255
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Do you mean the debugger, only display the date without
| the time because of is internal display format and in
| fact it does have the time but it is only not display??
Yes, that's what I means, because this datetime object that
does not have time can display time part.

|
| Following the reading of the link you send me, which
| format should be use to be the most standard in Canada
| and compatible with SQL server datetime field type?

I think you should use en-CA with the CultureInfo class, for
more information you can visit:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemGlobalizationCultureInfoClassTopic.asp

|
| Also I read some where that SQL server will accept the
| datetime string directly in a datetime field type, is
| that true ?

Yes, I have writen a sample code to insert the datetime object
to the sqlserver, it works well. It seems of that the sqlserver will
receive the datetime object and display it as it displayed in textbox
format.
|
| However, I still unable from the textbox field (datetime
| string) to add record in SQL, I always receive one error
| related to field type. I will do more tests tonight on
| this, and will try to see if it is not another field
| causing this error. I will post back here tomorrow.
|
| Thanks in advance.
|
| Carl,

Hope these help you

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6

P: n/a
I fix my issue.

It was related to the generic function I use to populate
the parameters object, one case was missing for the
datetime object.

Thanks for your help in this.

Carl,
-----Original Message-----

Hi Carl,

My reply in the line below:

--------------------
| Content-Class: urn:content-classes:message
| From: "Carl" <ca**@cb-cinc.com>
| Sender: "Carl" <ca**@cb-cinc.com>
| References: <29****************************@phx.gbl>
<32****************************@phx.gbl>
<26****************************@phx.gbl>
<R$**************@cpmsftngxa06.phx.gbl>
| Subject: RE: DateTime question
| Date: Mon, 8 Sep 2003 11:43:52 -0700
| Lines: 23
| Message-ID: <3d****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300| Thread-Index: AcN2OSZFy+I9EqXIS+uL4nwIYM3EEw==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183255| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Do you mean the debugger, only display the date without| the time because of is internal display format and in
| fact it does have the time but it is only not display??
Yes, that's what I means, because this datetime object thatdoes not have time can display time part.

|
| Following the reading of the link you send me, which
| format should be use to be the most standard in Canada
| and compatible with SQL server datetime field type?

I think you should use en-CA with the CultureInfo class, formore information you can visit:
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/cpref/html/frlrfSystemGlobalizationCultureInfoClassTopic.a sp

|
| Also I read some where that SQL server will accept the
| datetime string directly in a datetime field type, is
| that true ?

Yes, I have writen a sample code to insert the datetime objectto the sqlserver, it works well. It seems of that the sqlserver willreceive the datetime object and display it as it displayed in textboxformat.
|
| However, I still unable from the textbox field (datetime| string) to add record in SQL, I always receive one error| related to field type. I will do more tests tonight on| this, and will try to see if it is not another field
| causing this error. I will post back here tomorrow.
|
| Thanks in advance.
|
| Carl,

Hope these help you

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.