Saturday, March 31, 2012

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

Strange error mblè mblè :)


Dim SQL = "SELECT confermato, confrndnum FROM utenti WHERE confermato = 'false' AND confrndnum = " & Qs
Dim RsCommand = New OleDbCommand(Sql, Conn)
Dim RsRecordCount = RsCommand.ExecuteScalar()

If RsRecordCount = 0 Then
divErrEx.Visible = True
Else
SQL = "UPDATE utenti SET confermato = 'true' WHERE ConfRndNum = " & QS
RsCommand = New OleDbCommand(Sql, Conn)
RsCommand.ExecuteNonQuery()
Dim ReadCookie = Request.Cookies("tristizia_auth")
ltrUsername.Text = ReadCookie("Username")
divConfOp.Visible = TRUE
End If


the line "If RsRecordCount = 0 Then" gives error
The error is strange becouse if RsRecordCount is 0 the page works, if not it gives the error

Thanks for any answer
Bye
. AtariVerify that the following line is not returning NULL. If it is and you are trying to put it into a string then it won't work of course. The line below is defiantely your problem I think though.


ltrUsername.Text = ReadCookie("Username")

Ok tryed, but the error appears =

I tryed either so:


If RsRecordCount = 0 Then
divErrEx.Visible = True
Else
SQL = "UPDATE utenti SET confermato = 'true' WHERE ConfRndNum = " & QS
RsCommand = New OleDbCommand(Sql, Conn)
RsCommand.ExecuteNonQuery()
Dim ReadCookie = Request.Cookies("tristizia_auth")
If Not ReadCookie Is Nothing Then
ltrUsername.Text = ReadCookie("Username")
Else
ltrUsername.Text = "[Unsknown]"
End If
divConfOp.Visible = TRUE
End If

But however I get error either so :


If RsRecordCount = 0 Then
divErrEx.Visible = True
Else
Dim MyVar = "ewruowehr"
End If

Boh?!?!

Bye
. Atari
One more victim of the Visual Basic type sloppiness (which is a feature).
Try to Dim ReadCookie as HttpCookie, just to be sure you don't get a string instead.
Uhm nothing is changed...


Dim Conn = New OleDbConnection("Provider = Microsoft.Jet.OleDb.4.0;Data Source=" & Server.MapPath("/mdb-database/tristizia.mdb"))
Conn.Open()
Dim SQL = "SELECT confermato, confrndnum FROM utenti WHERE confermato = 'false' AND confrndnum = " & Qs
Dim RsCommand = New OleDbCommand(Sql, Conn)
Dim RsRecordCount = RsCommand.ExecuteScalar()

<b style="color:red;">If RsRecordCount = 0 Then</b>
divErrEx.Visible = True
Else
SQL = "UPDATE utenti SET confermato = 'true' WHERE ConfRndNum = " & QS
RsCommand = New OleDbCommand(Sql, Conn)
RsCommand.ExecuteNonQuery()
Dim ReadCookie As HttpCookie = Request.Cookies("tristizia_auth")
If Not ReadCookie Is Nothing Then
ltrUsername.Text = ReadCookie("Username")
Else
ltrUsername.Text = "[Sconosciuto]"
End If
divConfOp.Visible = TRUE
End If

But what's the problem? I need to declare AS [type] the variables ? If so what's RsRecordCount ? I tryed As Integer but doesn't work...

Bye
. Atari
It's always better to declare the type of your variables. Not declaring it is a source of bugs.
Why do you use ExecuteScalar here, whereas your query returns two different columns? ExecuteScalar returns the first column of the first row. Here, it would be confermato. Is this column an integer?
In this case, you can Dim RsRecordCount as Integer = CType(RsCommand.ExecuteScalar(), Integer), but I suspect this is not what you're trying to do...
Your query should probably be "SELECT COUNT(*) FROM utenti WHERE confermato = 'false' AND confrndnum = " & Qs

0 comments:

Post a Comment