Unusual conversion error (string to integer) asp.net
- by Phil
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.