adj
01-19-2009, 10:57 AM
Data source:
<asp:SqlDataSource ID="tblArticles" runat="server"
ConnectionString="<%$ ConnectionStrings:GNPConnectionString %>"
SelectCommand="SELECT articleid, articletitle, articledesc, pagename, convert(varchar,dateadded,101) as dateadded, active FROM tblArticles INNER JOIN tblPages on tblArticles.page = tblPages.pagenamekey WHERE active=1"
UpdateCommand="UPDATE tblArticles SET articletitle=@articletitle, articledesc=@articledesc WHERE articleid=@articleid"
DeleteCommand="UPDATE tblArticles SET active=0 WHERE articleid=@articleid">
</asp:SqlDataSource>
Gridview:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="tblArticles" ShowFooter="True" >
<Columns>
<asp:BoundField DataField="articleid" HeaderText="ID"
SortExpression="articleid" ReadOnly="true" />
<asp:BoundField DataField="articletitle" HeaderText="Title"
SortExpression="articletitle" />
<asp:BoundField DataField="articledesc" HeaderText="Description"
SortExpression="articledesc" />
<asp:BoundField DataField="dateadded" HeaderText="Date Added"
SortExpression="dateadded" ReadOnly="true" />
<asp:BoundField DataField="active" HeaderText="Active"
SortExpression="active" Visible="false" />
<asp:CommandField Visible="true" ShowEditButton="true" ShowCancelButton="true" ShowDeleteButton="true" HeaderText="Admin" />
</Columns>
</asp:GridView>
I get this error:
Error: Sys.WebForms.PageRequestManagerServerErrorException: Must declare the variable '@articleid'.
I thought if you used the names in the gridview in your sql statements in the data source, they didn't need to be declared elsewhere. So why the error?
<asp:SqlDataSource ID="tblArticles" runat="server"
ConnectionString="<%$ ConnectionStrings:GNPConnectionString %>"
SelectCommand="SELECT articleid, articletitle, articledesc, pagename, convert(varchar,dateadded,101) as dateadded, active FROM tblArticles INNER JOIN tblPages on tblArticles.page = tblPages.pagenamekey WHERE active=1"
UpdateCommand="UPDATE tblArticles SET articletitle=@articletitle, articledesc=@articledesc WHERE articleid=@articleid"
DeleteCommand="UPDATE tblArticles SET active=0 WHERE articleid=@articleid">
</asp:SqlDataSource>
Gridview:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="tblArticles" ShowFooter="True" >
<Columns>
<asp:BoundField DataField="articleid" HeaderText="ID"
SortExpression="articleid" ReadOnly="true" />
<asp:BoundField DataField="articletitle" HeaderText="Title"
SortExpression="articletitle" />
<asp:BoundField DataField="articledesc" HeaderText="Description"
SortExpression="articledesc" />
<asp:BoundField DataField="dateadded" HeaderText="Date Added"
SortExpression="dateadded" ReadOnly="true" />
<asp:BoundField DataField="active" HeaderText="Active"
SortExpression="active" Visible="false" />
<asp:CommandField Visible="true" ShowEditButton="true" ShowCancelButton="true" ShowDeleteButton="true" HeaderText="Admin" />
</Columns>
</asp:GridView>
I get this error:
Error: Sys.WebForms.PageRequestManagerServerErrorException: Must declare the variable '@articleid'.
I thought if you used the names in the gridview in your sql statements in the data source, they didn't need to be declared elsewhere. So why the error?