G
Guest
I've chosen to implement the "optimistic concurrency" model in my
application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to
my main tables. I read the value of the column in my select, remember it, and
then use it in the update. It works just fine when I have full control of the
whole process.
I want to do the same for my GridView/SqlDataSource combinations. I
typically select from a view and update the corresponding table.
Simply adding a RowVersion column to my GridView and @RowVersion to the
UpdateCommand results in a [Must declare the scalar variable "@RowVersion"]
error.
The other columns auto magically get carried over from the select into the
update, why doesn't the RowVersion?
Here's the code:
<asp:GridView ID="GridViewSharePartners" runat="server"
AutoGenerateColumns="False"
DataKeyNames="dbIDAntennaOwner,dbIDSite"
DataSourceID="SharePartnerList" EmptyDataText="No Partners on record for this
Site"
Width="549px"
OnRowEditing="GridViewSharePartners_RowEditing" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="dbIDSite"
HeaderText="dbIDSite" ReadOnly="True" SortExpression="dbIDSite"
Visible="False" />
<asp:BoundField DataField="dbIDAntennaOwner"
HeaderText="dbIDAntennaOwner" ReadOnly="True"
SortExpression="dbIDAntennaOwner" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name"
ReadOnly="True" SortExpression="Name" />
<asp:BoundField DataField="PartnerSiteID"
HeaderText="PartnerSiteID" SortExpression="PartnerSiteID" />
<asp:BoundField DataField="Comments"
HeaderText="Comments" SortExpression="Comments" />
<asp:BoundField DataField="RowVersion"
HeaderText="RowVersion" SortExpression="RowVersion" ReadOnly="True"
Visible="False" />
</Columns>
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
<asp:SqlDataSource ID="SharePartnerList" runat="server"
ConnectionString="<%$ ConnectionStrings:VodacomEMRConnectionString %>"
SelectCommand="SELECT * FROM vw_SharePartner WHERE
dbIDSite = @siteID"
UpdateCommand="UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite =
@dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
<UpdateParameters>
<asp:SessionParameter Name="userName"
SessionField="UserName" Type="String" />
<asp:QueryStringParameter Name="siteID"
QueryStringField="siteID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="siteID"
QueryStringField="siteID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to
my main tables. I read the value of the column in my select, remember it, and
then use it in the update. It works just fine when I have full control of the
whole process.
I want to do the same for my GridView/SqlDataSource combinations. I
typically select from a view and update the corresponding table.
Simply adding a RowVersion column to my GridView and @RowVersion to the
UpdateCommand results in a [Must declare the scalar variable "@RowVersion"]
error.
The other columns auto magically get carried over from the select into the
update, why doesn't the RowVersion?
Here's the code:
<asp:GridView ID="GridViewSharePartners" runat="server"
AutoGenerateColumns="False"
DataKeyNames="dbIDAntennaOwner,dbIDSite"
DataSourceID="SharePartnerList" EmptyDataText="No Partners on record for this
Site"
Width="549px"
OnRowEditing="GridViewSharePartners_RowEditing" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="dbIDSite"
HeaderText="dbIDSite" ReadOnly="True" SortExpression="dbIDSite"
Visible="False" />
<asp:BoundField DataField="dbIDAntennaOwner"
HeaderText="dbIDAntennaOwner" ReadOnly="True"
SortExpression="dbIDAntennaOwner" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name"
ReadOnly="True" SortExpression="Name" />
<asp:BoundField DataField="PartnerSiteID"
HeaderText="PartnerSiteID" SortExpression="PartnerSiteID" />
<asp:BoundField DataField="Comments"
HeaderText="Comments" SortExpression="Comments" />
<asp:BoundField DataField="RowVersion"
HeaderText="RowVersion" SortExpression="RowVersion" ReadOnly="True"
Visible="False" />
</Columns>
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
<asp:SqlDataSource ID="SharePartnerList" runat="server"
ConnectionString="<%$ ConnectionStrings:VodacomEMRConnectionString %>"
SelectCommand="SELECT * FROM vw_SharePartner WHERE
dbIDSite = @siteID"
UpdateCommand="UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite =
@dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
<UpdateParameters>
<asp:SessionParameter Name="userName"
SessionField="UserName" Type="String" />
<asp:QueryStringParameter Name="siteID"
QueryStringField="siteID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="siteID"
QueryStringField="siteID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>