各位师兄,帮帮忙!

nimeila 2012-05-19 07:59:56
我想;批量更新 成绩 ,但运行时提示 update语句语法错误 数据库中成绩字段为int型,学号为字符型,课程代码为int型
protected void Button1_Click(object sender, EventArgs e)
{
int rowCount = GridView1.Rows.Count;

OleDbCommand comm;
for (int i = 0; i < rowCount; i++)
{
connection = new OleDbConnection(ConnStr);
GridViewRow row = GridView1.Rows[i];
string StuID = row.Cells[1].Text;
string ClassID = row.Cells[2].Text;
TextBox tb = (TextBox)row.Cells[3].FindControl("cj");
string score = tb.Text.ToString();
comm = new OleDbCommand("update score2 set 成绩=" + score + " where 学号='" + StuID + "' and 课程代码="+ ClassID +"", connection);
connection.Open();
comm.ExecuteNonQuery();
connection.Close();
}
...全文
172 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-05-20
  • 打赏
  • 举报
回复
首先调试score StuID ClassID 是否取到了值?
另外 sql语句改成如下试试
comm = new OleDbCommand("update score2 set [成绩]=" + Convert.ToInt32(score) + " where [学号]='" + StuID + "' and [课程代码]="+ Convert.ToInt32(ClassID), connection);
  • 打赏
  • 举报
回复
单步调试一下,看看取的值有没有错。
nimeila 2012-05-20
  • 打赏
  • 举报
回复
各位师兄,都不行啊!
nimeila 2012-05-20
  • 打赏
  • 举报
回复
谢谢各位!解决了!
yy5408408 2012-05-19
  • 打赏
  • 举报
回复
int score=convert.toInt32((gvID.rows[i].findControl("cj") as TextBox).Text);
yy5408408 2012-05-19
  • 打赏
  • 举报
回复
rows[i] ......少了个s
yy5408408 2012-05-19
  • 打赏
  • 举报
回复
TextBox tb = (TextBox)row.Cells[3].FindControl("cj");
string score = tb.Text.ToString();
改成
int score=convert.toInt32(gvID.row[i].findControl("cj") as TextBox);
huijunliang 2012-05-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
comm = new OleDbCommand("update score2 set 成绩=" + int.Parse(score) + " where 学号='" + StuID + "' and 课程代码="+ int.Parse(ClassID), connection);
[/Quote]

+1

暖枫无敌 2012-05-19
  • 打赏
  • 举报
回复
comm = new OleDbCommand("update score2 set 成绩=" + int.Parse(score) + " where 学号='" + StuID + "' and 课程代码="+ int.Parse(ClassID), connection);

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧