Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. String to integer Conversion

String to integer Conversion

Scheduled Pinned Locked Moved ASP.NET
helpquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kissy16
    wrote on last edited by
    #1

    Hai to all, Till now i have used the function for converting the string values to integer as Integer.parse(txtnumber.text) and also used Int32.parse(txtnumber.text) And now it is giving an error like "Input string was not in a correct Format". What might be the reason for it is working for some forms and not for others.CAn anyone tell me in what cases it will give this type of error??

    kissy

    V M 2 Replies Last reply
    0
    • K Kissy16

      Hai to all, Till now i have used the function for converting the string values to integer as Integer.parse(txtnumber.text) and also used Int32.parse(txtnumber.text) And now it is giving an error like "Input string was not in a correct Format". What might be the reason for it is working for some forms and not for others.CAn anyone tell me in what cases it will give this type of error??

      kissy

      V Offline
      V Offline
      VaibhavTiparadi
      wrote on last edited by
      #2

      it gives the error only when txtnumber.text contains characters other than digit. before converting string value to integer u need to validate the input string.... by say regular exp... Regex reNo = new Regex(@"^[0-9]{*}$"); if (reNo.Match(txtnumber.text).Success == false) { //display err. msg. "invalid data" } else { //Convert to integer Int32.parse(txtnumber.text) } ///this way it will not give run time err.

      K 1 Reply Last reply
      0
      • K Kissy16

        Hai to all, Till now i have used the function for converting the string values to integer as Integer.parse(txtnumber.text) and also used Int32.parse(txtnumber.text) And now it is giving an error like "Input string was not in a correct Format". What might be the reason for it is working for some forms and not for others.CAn anyone tell me in what cases it will give this type of error??

        kissy

        M Offline
        M Offline
        Muhammad Faisal Khanani
        wrote on last edited by
        #3

        if the text of your textbox(txtnumber) has an empty string it would give the above error, because becomes unable to parse it into integer.

        K 1 Reply Last reply
        0
        • V VaibhavTiparadi

          it gives the error only when txtnumber.text contains characters other than digit. before converting string value to integer u need to validate the input string.... by say regular exp... Regex reNo = new Regex(@"^[0-9]{*}$"); if (reNo.Match(txtnumber.text).Success == false) { //display err. msg. "invalid data" } else { //Convert to integer Int32.parse(txtnumber.text) } ///this way it will not give run time err.

          K Offline
          K Offline
          Kissy16
          wrote on last edited by
          #4

          DEar Vaibhav, Thanks for ur reply,Ur suggestion is good,but even when i am entering digits then only it is giving error. I have more than 10 textboxes for entering digits into textboxes and need to convert them into integer values for the database in my webform. But it is not possible for giving RegExp for all these textboxes in a single form??Isn't it?? I am using VB in my aps.net. What to do??? Actully here i have kept all the textboxes in a table,Is it makes any difference???If the textbox is not in the table(in open) then it is not giveng any error??? -- modified at 2:12 Monday 26th March, 2007

          kissy

          V 1 Reply Last reply
          0
          • K Kissy16

            DEar Vaibhav, Thanks for ur reply,Ur suggestion is good,but even when i am entering digits then only it is giving error. I have more than 10 textboxes for entering digits into textboxes and need to convert them into integer values for the database in my webform. But it is not possible for giving RegExp for all these textboxes in a single form??Isn't it?? I am using VB in my aps.net. What to do??? Actully here i have kept all the textboxes in a table,Is it makes any difference???If the textbox is not in the table(in open) then it is not giveng any error??? -- modified at 2:12 Monday 26th March, 2007

            kissy

            V Offline
            V Offline
            VaibhavTiparadi
            wrote on last edited by
            #5

            Then in this case u can use Regular exp. validators for each textbox.. and also pls update the reg. exp. to "^[0-9]*$".. and about placing things in table would not make any difference...

            1 Reply Last reply
            0
            • M Muhammad Faisal Khanani

              if the text of your textbox(txtnumber) has an empty string it would give the above error, because becomes unable to parse it into integer.

              K Offline
              K Offline
              Kissy16
              wrote on last edited by
              #6

              Hai, Thaks for ur reply.But my doubt is Even i am entering some value into thetextbox it is giving blank when i am parsing the data. How it is happening.Means it is nothin is coming into the textbox while conversion. Can u give me some idea.

              kissy

              V 1 Reply Last reply
              0
              • K Kissy16

                Hai, Thaks for ur reply.But my doubt is Even i am entering some value into thetextbox it is giving blank when i am parsing the data. How it is happening.Means it is nothin is coming into the textbox while conversion. Can u give me some idea.

                kissy

                V Offline
                V Offline
                VaibhavTiparadi
                wrote on last edited by
                #7

                can u pls show me ur code... so that i can help u out.

                K 1 Reply Last reply
                0
                • V VaibhavTiparadi

                  can u pls show me ur code... so that i can help u out.

                  K Offline
                  K Offline
                  Kissy16
                  wrote on last edited by
                  #8

                  Hai, Try Dim str As String = txtseedno.Text Dim dtrs As Integer = Convert.ToInt32(str) Response.Write(dtrs) Response.End() Catch ex As Exception Response.Write(ex.Message) End Try Also i have tried with integer.parse(str) But it is giving error because it is having blank value.I have taken this textbox in a table. and simply i am showin on button click event

                  kissy

                  V M 2 Replies Last reply
                  0
                  • K Kissy16

                    Hai, Try Dim str As String = txtseedno.Text Dim dtrs As Integer = Convert.ToInt32(str) Response.Write(dtrs) Response.End() Catch ex As Exception Response.Write(ex.Message) End Try Also i have tried with integer.parse(str) But it is giving error because it is having blank value.I have taken this textbox in a table. and simply i am showin on button click event

                    kissy

                    V Offline
                    V Offline
                    VaibhavTiparadi
                    wrote on last edited by
                    #9

                    hey pls send me ur email id ...so that i can send u sample project..which works..k

                    1 Reply Last reply
                    0
                    • K Kissy16

                      Hai, Try Dim str As String = txtseedno.Text Dim dtrs As Integer = Convert.ToInt32(str) Response.Write(dtrs) Response.End() Catch ex As Exception Response.Write(ex.Message) End Try Also i have tried with integer.parse(str) But it is giving error because it is having blank value.I have taken this textbox in a table. and simply i am showin on button click event

                      kissy

                      M Offline
                      M Offline
                      Muhammad Faisal Khanani
                      wrote on last edited by
                      #10

                      Try this, Dim str As String=txtseedno.Text Dim dtrs As Integer=0 If str.Length > 0 Then dtrs=Integer.Parse(str) End If response.write(dtrs) but, your txtseedno (textbox) should be validate thorough regular expression validator.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups