Few syntax questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl

    #1

    Few syntax questions

    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.T oLongTimeString ();
    give the error Cannot convert type 'string'
    to 'System.DateTim e'

    Carl,

  • Carl

    #2
    Few syntax questions

    I find it,

    For decimal,

    Convert.ToDecim al(txtTOTAL.Tex t)

    For datetime,

    Convert.ToDateT ime(txtDATEFAC. Text)

    Carl,

    [color=blue]
    >-----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[/color]
    do[color=blue]
    >you convert back the text enter by user into datetime ?
    >
    >txtDATEFAC.Tex t=DateTime.Now. ToLongTimeStrin g();
    >give the error Cannot convert type 'string'
    >to 'System.DateTim e'
    >
    >Carl,
    >
    >.
    >[/color]

    Comment

    • Carl

      #3
      DateTime question

      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.T oString();

      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.ToDateT ime(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.To String(); or in a way SQL server
      will recognize.

      Thanks in advance..

      Carl,

      Comment

      • Jeffrey Tan[MSFT]

        #4
        RE: DateTime question


        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/
        frlrfSystemGlob alizationDateTi meFormatInfoCla ssTopic.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" <Carl@cb-cinc.com>
        | Sender: "Carl" <Carl@cb-cinc.com>
        | References: <29e401c373e7$0 2744600$a001280 a@phx.gbl>
        <32bd01c37408$a 8d55720$a401280 a@phx.gbl>
        | Subject: DateTime question
        | Date: Fri, 5 Sep 2003 19:01:37 -0700
        | Lines: 24
        | Message-ID: <265301c3741a$c e6bf860$a301280 a@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: AcN0Gs5rXd9kxnE MRAu1G1IeqY2/Vw==
        | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        | Path: cpmsftngxa06.ph x.gbl
        | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1827 83
        | NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
        | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.T oString();
        |
        | 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.ToDateT ime(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.To String(); or in a way SQL server
        | will recognize.
        |
        | Thanks in advance..
        |
        | Carl,
        |
        |

        Comment

        • Carl

          #5
          RE: DateTime question

          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,
          [color=blue]
          >[/color]

          Comment

          • Jeffrey Tan[MSFT]

            #6
            RE: DateTime question


            Hi Carl,

            My reply in the line below:

            --------------------
            | Content-Class: urn:content-classes:message
            | From: "Carl" <carl@cb-cinc.com>
            | Sender: "Carl" <carl@cb-cinc.com>
            | References: <29e401c373e7$0 2744600$a001280 a@phx.gbl>
            <32bd01c37408$a 8d55720$a401280 a@phx.gbl>
            <265301c3741a$c e6bf860$a301280 a@phx.gbl>
            <R$TfEwbdDHA.21 16@cpmsftngxa06 .phx.gbl>
            | Subject: RE: DateTime question
            | Date: Mon, 8 Sep 2003 11:43:52 -0700
            | Lines: 23
            | Message-ID: <3dad01c37639$2 64538b0$a301280 a@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+I9EqX IS+uL4nwIYM3EEw ==
            | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            | Path: cpmsftngxa06.ph x.gbl
            | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1832 55
            | NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
            | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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/
            frlrfSystemGlob alizationCultur eInfoClassTopic .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.

            Comment

            • Carl

              #7
              RE: DateTime question

              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,


              [color=blue]
              >-----Original Message-----
              >
              >Hi Carl,
              >
              >My reply in the line below:
              >
              >--------------------
              >| Content-Class: urn:content-classes:message
              >| From: "Carl" <carl@cb-cinc.com>
              >| Sender: "Carl" <carl@cb-cinc.com>
              >| References: <29e401c373e7$0 2744600$a001280 a@phx.gbl>
              ><32bd01c37408$ a8d55720$a40128 0a@phx.gbl>
              ><265301c3741a$ ce6bf860$a30128 0a@phx.gbl>
              ><R$TfEwbdDHA.2 116@cpmsftngxa0 6.phx.gbl>
              >| Subject: RE: DateTime question
              >| Date: Mon, 8 Sep 2003 11:43:52 -0700
              >| Lines: 23
              >| Message-ID: <3dad01c37639$2 64538b0$a301280 a@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[/color]
              V5.50.4910.0300[color=blue]
              >| Thread-Index: AcN2OSZFy+I9EqX IS+uL4nwIYM3EEw ==
              >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              >| Path: cpmsftngxa06.ph x.gbl
              >| Xref: cpmsftngxa06.ph x.gbl[/color]
              microsoft.publi c.dotnet.langua ges.csharp:1832 55[color=blue]
              >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
              >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              >|
              >| Do you mean the debugger, only display the date[/color]
              without[color=blue]
              >| 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[/color]
              object that[color=blue]
              >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[/color]
              class, for[color=blue]
              >more information you can visit:
              >http://msdn.microsoft.com/library/default.asp?[/color]
              url=/library/en-us/cpref/html/[color=blue]
              >frlrfSystemGlo balizationCultu reInfoClassTopi c.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[/color]
              datetime object[color=blue]
              >to the sqlserver, it works well. It seems of that the[/color]
              sqlserver will[color=blue]
              >receive the datetime object and display it as it[/color]
              displayed in textbox[color=blue]
              >format.
              >
              >
              >|
              >| However, I still unable from the textbox field[/color]
              (datetime[color=blue]
              >| string) to add record in SQL, I always receive one[/color]
              error[color=blue]
              >| related to field type. I will do more tests tonight[/color]
              on[color=blue]
              >| 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[/color]
              confers no rights.[color=blue]
              >
              >.
              >[/color]

              Comment

              Working...