本文介绍了我想更新一个 num 参数并将其汇总到我的数据库中...遇到问题... Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新一个球员的进球数,所以如果他进球了,我想更新他的进球数......我的代码中有一个错误,我不知道如何修复它.谁能帮我解决一下,好吗?

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?

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

我的 HTML 代码:

 <asp:GridView ID="SoccerTable" runat="server" AutoGenerateColumns="False"
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
        CellPadding="3" DataSourceID="AccessDataSource1">
        <Columns>
            <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="הישגים">
                <ItemTemplate>
                    <asp:DropDownList ID="AchNums" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
                <asp:ListItem>6</asp:ListItem>
                <asp:ListItem>7</asp:ListItem>
                <asp:ListItem>8</asp:ListItem>
                <asp:ListItem>9</asp:ListItem>
                <asp:ListItem>10</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
                  <FooterTemplate>
                 <asp:TextBox ID="txtAchNumsFooter" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                <ItemTemplate>
                 <asp:Button class = "AddButton" ID="AddButton" runat="server" onclick="AddButton_Click" Text="עדכן" />
                </ItemTemplate>
                </asp:TemplateField>
        </Columns>

我的问题:输入字符串的格式不正确.

My Problem: Input string was not in the correct format.

请帮帮我:(

推荐答案

@Alex 好像是行的格式异常int a = int.Parse((SoccerTable.FooterRow.FindControl("txtAchNumsFooter") as TextBox).Text.Trim());.

@Alex It seems to be like a format exception at the line int a = int.Parse((SoccerTable.FooterRow.FindControl("txtAchNumsFooter") as TextBox).Text.Trim());.

在您的情况下,文本框返回的值可能不是有效的整数值.这就是您收到此错误的原因.

In your case, the possibility is that the value return by the textbox is not a valid integer value. Thats why you are getting this error.

您能否尝试调试您的代码并对这条语句 'SoccerTable.FooterRow.FindControl("txtAchNumsFooter") as TextBox).Text.Trim()' 进行快速观察.检查你得到了什么.

Can you try debugging your code and do quickwatch on this statement 'SoccerTable.FooterRow.FindControl("txtAchNumsFooter") as TextBox).Text.Trim()'. Check what you get.

这篇关于我想更新一个 num 参数并将其汇总到我的数据库中...遇到问题... Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:48