looking for some solutions? You are welcome.

SOLVED: Still have problems with gridview and update for my database project


I want to Update An Number of goals That a Player Scored so if he socred a goal I want to do an update for his number of goals... I got an Error in my Code And I don't know how to fix it. Can anyone help me to fix it, please ?

My Code:

        string connectionStr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\SoccerDataBase.mdb";
    using (OleDbConnection sqlCon = new OleDbConnection(connectionStr))
        string queryStr = "SELECT Achievement FROM SoccerAchievements WHERE UserID=@AchNums";
        OleDbCommand sqlCmd = new OleDbCommand(queryStr, sqlCon);
        sqlCmd.Parameters.AddWithValue("@AchNums", (SoccerTable.FooterRow.FindControl("AchNums") as TextBox).Text.Trim());
        OleDbDataAdapter dataAdapt = new OleDbDataAdapter(queryStr, sqlCon);
        DataSet ds = new DataSet();
        dataAdapt.Fill(ds, "SoccerAchievement");
        DataRow row = ds.Tables["SoccerAchievement"].Rows[0];
        int a = int.Parse(row[3].ToString());
        a = a + int.Parse("@AchNums");
        string query = "UPDATE SoccerAchievements SET Achievement= '" + a + "' WHERE UserID= @AchNums";

My GridView HTML CODE:

<asp:GridView ID="SoccerTable" runat="server" AutoGenerateColumns="False" 
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" DataSourceID="AccessDataSource1">
            <asp:BoundField DataField="ID" HeaderText="קוד שחקן" InsertVisible="False" 
                SortExpression="ID" />
            <asp:BoundField DataField="Team" HeaderText="קבוצות" SortExpression="Team" />
            <asp:BoundField DataField="Players" HeaderText="שחקנים" 
                SortExpression="Players" />
                <asp:TemplateField HeaderText="הישגים">
                <asp:TextBox ID="AchNums" runat="server"></asp:TextBox>
                 <asp:Button class = "AddButton" ID="AddButton" runat="server" onclick="AddButton_Click" Text="עדכן" />
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#007DBB" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#00547E" />

My Error: There is no row at position 0. Image:

enter image description here

My Data SoccerAchievements

Image: enter image description here

Please help me guys :)

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots

No comments: