I have a problem that I have been trying to tackle for the last 24 hours so to avoid me going insane I thought I’d ask someone for help with my problem!
I am using Visual Web Developer, and in this I have an asp Gridview element which selects information from my AccessDataSource. (Which I might add works perfectly fine.)
My error comes when I try to update the information in the Gridview. My update SQL works fine in Access, however in VWD it throws no error message but fails to save the new data to the database. I have set the parameters in asp for the update command, and I have the ‘DataKeyNames’ set, too.
Can anyone help me with this? I am relatively new to this and I just can’t see where I am going wrong. I have been doing extensive searching online for a good while and still couldn’t quite see it, so I thought my next best shot was to ask on here.
Many thanks in advance. 🙂
My ASP.net code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" DataKeyNames="MemberID"
style="z-index: 1; left: 0px; top: 147px; position: absolute; height: 133px;
width:499px">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="RaceID" HeaderText="RaceID" SortExpression="RaceID" />
<asp:BoundField DataField="MemberID" HeaderText="MemberID" SortExpression="MemberID" />
<asp:BoundField DataField="MemberName" HeaderText="MemberName"
SortExpression="MemberName" />
<asp:BoundField DataField="PersonalTime" HeaderText="PersonalTime"
SortExpression="PersonalTime" />
<asp:BoundField DataField="FinishPosition" HeaderText="FinishPosition"
SortExpression="FinishPosition" />
<asp:BoundField DataField="Points" HeaderText="Points"
SortExpression="Points" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/myDatabase.mdb"
SelectCommand="SELECT tblResult.RaceID, tblResult.MemberID, tblMember.MemberName,
tblResult.PersonalTime, tblResult.FinishPosition, tblPoint.Points FROM ((tblRaceType
INNER JOIN (tblRace INNER JOIN (tblMember INNER JOIN tblResult ON tblMember.MemberID =
tblResult.MemberID) ON tblRace.RaceID = tblResult.RaceID) ON tblRaceType.RaceTypeID =
tblRace.RaceTypeID) INNER JOIN tblPoint ON tblResult.FinishPosition = tblPoint.
[Position] AND tblRaceType.RaceTypeID = tblPoint.RaceTypeID) WHERE (tblResult.RaceID =
?) AND (tblPoint.RaceTypeID = ?) ORDER BY tblResult.FinishPosition"
UpdateCommand="UPDATE [tblResult] SET PersonalTime = ?, FinishPosition = ? WHERE
MemberID = ? AND RaceID = ?">
<SelectParameters>
<asp:SessionParameter DefaultValue="0" Name="?" SessionField="raceID" />
<asp:SessionParameter DefaultValue="0" Name="?" SessionField="raceTypeID" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PersonalTime" Type="String"/>
<asp:Parameter Name="FinishPosition" Type="Int64" />
<asp:Parameter Name="MemberID" Type="Int64" />
<asp:Parameter Name="RaceID" Type="Int64" />
</UpdateParameters>
</asp:AccessDataSource>
For anyone else with the same problem:
I had to just wrap my already existing VB code in “If Not Page.IsPostBack”. Think this was interfering with the Update by re-loading the page and before it got to execute the Update command.