Few syntax questions

  • Thread starter Thread starter Carl
  • Start date Start date
C

Carl

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,
 
I find it,

For decimal,

Convert.ToDecimal(txtTOTAL.Text)

For datetime,

Convert.ToDateTime(txtDATEFAC.Text)

Carl,
 
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,
 
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/default.asp?url=/library/en-us/cpref/html/
frlrfSystemGlobalizationDateTimeFormatInfoClassTopic.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" <[email protected]>
| Sender: "Carl" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: DateTime question
| Date: Fri, 5 Sep 2003 19:01:37 -0700
| Lines: 24
| Message-ID: <[email protected]>
| 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,
|
|
 
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,
 
Hi Carl,

My reply in the line below:

--------------------
| Content-Class: urn:content-classes:message
| From: "Carl" <[email protected]>
| Sender: "Carl" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: DateTime question
| Date: Mon, 8 Sep 2003 11:43:52 -0700
| Lines: 23
| Message-ID: <[email protected]>
| 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/default.asp?url=/library/en-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.
 
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,
 
Back
Top