Unusual conversion error (string to integer) asp.net
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-04-20T06:51:22Z
Indexed on
2010/04/20
6:53 UTC
Read the original article
Hit count: 164
I have my repeater item template:
<ItemTemplate>
<tr><td><%#Container.DataItem("Category")%></td></tr>
</ItemTemplate>
Hooked up to:
s = "SQL that works ok on server"
x = New SqlCommand(s, c)
x.Parameters.Add("@contentid", SqlDbType.Int)
x.Parameters("@contentid").Value = contentid
c.Open()
r = x.ExecuteReader
If r.HasRows Then
Linksrepeater.DataSource = r
Linksrepeater.DataBind()
End If
c.Close()
r.Close()
When I run the code I get: Invalid Cast Exception was not handled by user code (Conversion from string "category" to type 'Integer' is not valid.)
I'm not sure how / why it is trying to convert "Category" to integer as in the db it is a string.
Can you please tell me how to avoid this error? thanks.
© Stack Overflow or respective owner