0
我有我的repeater項目模板:異常轉換錯誤(字符串整數)asp.net
<asp:Repeater ID="Linksrepeater" runat="server">
<HeaderTemplate><h2>Links</h2><ul>
</HeaderTemplate>
<ItemTemplate>
<li><%#Container.DataItem("Category")%></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
迷上了:
s = "sql"
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()
當我運行的代碼我得到:
用戶代碼未處理無效的投射異常(從 字符串「category」轉換爲類型「Integer」無效。)
我不知道如何/爲什麼它試圖將Category
轉換爲整數,就像在db中它是一個字符串一樣。
你能告訴我如何避免這個錯誤?謝謝。
編輯:如果我嘗試<%#Container.DataItem("URL")%>
要在這裏需要一個完整的代碼示例,包括SQL字符串。 – 2010-04-20 06:54:03
是的,你認爲的工作可能是什麼不工作,這就是爲什麼你在這裏,對嗎? ;-)發佈中繼器的sql和標記。 – 2010-04-20 06:55:55