我想更新和汇总一个数字参数到我的数据库...有问题... Gridview [英] I want to update and sum a num paramter to my database... Got Problem... 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代码:
My HTML Code:
<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)作为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.
这篇关于我想更新和汇总一个数字参数到我的数据库...有问题... Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!