Saturday, March 31, 2012

String to Int error

Hello,

I need to convert a value from my textbox from string to int. It only hold the idea of an item and i need to send that as Stored Procedure value to fetch another value.
I now get the current error:

Input string was not in a correct format.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.FormatException: Input string was not in a correct format.

Source Error:

Line 97: Dim strComm As String = "spQMelderStatusGet"
Line 98: Dim str As String = Convert.ToString(lblStatus.Text)
Line 99: Dim ID As Int32 = Int32.Parse(str)
Line 100: Using loStat As SqlCommand = New SqlCommand(strComm)
Line 101:


Source File:D:\Source\Qualm\QMelder\StatusViewer.aspx.vb Line:99

And this is the code i'm using:

'Get status naamDim strCommAs String ="spQMelderStatusGet"Dim strAs String = Convert.ToString(lblStatus.Text)
Dim IDAs Int32 = Int32.Parse(str)
Using loStatAs SqlCommand =New SqlCommand(strComm)

Dim StatIDAs New SqlParameter()
StatID.ParameterName ="@dotnet.itags.org.StatusID" StatID.SqlDbType = SqlDbType.Int StatID.Direction = ParameterDirection.InputOutput StatID.Size = 2 StatID.Value = ID loStat.Parameters.Add(StatID) loStat.Connection = loConn loStat.CommandType = CommandType.StoredProcedure statReader = loStat.ExecuteReader lblStatus.Text = statReader("StatusNaam")
End Using

statReader.Close()


I've tried all kinds of ways, like converting the txtbox value to string and then to int but keep giving the same error, so most likely those codes weren't the right ones either.

If someone could help me out, tnx alot in advance.

Anoiks

Hi

before parsing String value in integer, check it's value ..

i hope . in ur case it's value is NULL or any Literal word


Hi

Hope I have understood your problem correctly.

Have you tried Convert.ToInt32("string").

But as I write, If the parse function you used fails to convert the string to integer, then may be the value entered in the text box either is non-convertible to integer data type or a conversion results in a out of range value. If you beleive it is a large integer value, can you try using a "float" or a "double" data type.

Worse case, can you convert your stored procedure type to accept an integer, I hope that is not hindering your requirement.

VJ


ok that was a stupid mistake, thanks alot i was too focussed on that part of code.
So i didnt notice i didnt fill the string in codes before that.Geeked

0 comments:

Post a Comment