我从 url 获取 id 并将其传递给 sqldatasource - selectcommand 我收到以下错误:
Conversion failed when converting the varchar value '<%=MyIdVal%>'
to data type int.
后面的代码:
Public Partial Class Edit
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyIdVal = Request.QueryString("id")
End Sub
Private _myIdVal As Integer
Public Property MyIdVal() As Integer
Get
Return _myIdVal
End Get
Set(ByVal value As Integer)
_myIdVal = value
End Set
End Property
结束类
客户 :
< head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%=MyIdVal%>
</div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="myIdDataSource">
</asp:GridView>
<asp:SqlDataSource runat="server" ID="myIdDataSource"
ConnectionString="<%$ ConnectionStrings:myCipConnection %>"
ProviderName="<%$ ConnectionStrings:myCipConnection.ProviderName %>"
SelectCommand="SELECT * FROM books WHERE id = '<%=MyIdVal%>'" >
</asp:SqlDataSource>
</form>
</body>
</html>
当我对其进行硬编码时,代码运行良好,知道如何解决此错误,谢谢