| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 819 人关注过本帖
标题:[求助] 哪位大侠可以帮帮小弟我看看这段代码哪里出问题啊??
只看楼主 加入收藏
joesoon
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-5-19
收藏
 问题点数:0 回复次数:0 
[求助] 哪位大侠可以帮帮小弟我看看这段代码哪里出问题啊??

小弟这几天在写一个图书管理软件,下面代码是借书按键的功能实现。 不过出现了一个问题:下面的代码中"update tblbook set amount=amount-1 where bookID='" & Trim(Txtbookid2.Text) & "'"这一句执行了两次。 比如:原来数据是10,我按了按钮后想让它等于9,可是当我按钮后却等于8. sql语句我验证过没错,不知道是哪里发生的错误。 大侠们请帮帮我啊~~~~~~555...... Private Sub Btbrw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btbrw.Click

'如果是借书时确认,即“借书”按钮已经变成了“确认”按钮 If Btbrw.Text = "确认" Then '保存借书时当前显示的记录号 Dim currentPos As Integer = Me.BindingContext(Ds2, "tblborrow").Position '弹出警告框,如果用户单击“确定”,那么 If MessageBox.Show("确定借书吗?", "借书-确认", MessageBoxButtons.OKCancel) = DialogResult.OK Then If Trim(Txtbookid2.Text) = "" Then MessageBox.Show("书的编号不能为空!") Return End If

Dim selshlid As String = "select * from tblbook where amount='0' and bookID='" & Trim(Txtbookid2.Text) & "'" '打开连接,并执行查询 OleDbConnection2.Open() ODAcmd2.SelectCommand.CommandText = selshlid ODAcmd2.SelectCommand.ExecuteNonQuery() '重新填充数据集,并关闭连接 Ds.Clear() ODAcmd2.Fill(Ds, "tblbook") OleDbConnection2.Close()

Dim iCnt As Integer Dim iPos As Integer '总共有多少条记录 iCnt = Me.BindingContext(Ds, "tblbook").Count If iCnt = 0 Then

Dim scertificateid As String = "'" & TxtshlID.Text & "'" Dim slibid As String = "'" & TxtlibID.Text & "'" Dim sname As String = "'" & Txtname.Text & "'" Dim sbookid As String = "'" & Txtbookid2.Text & "'" Dim sbookname As String = "'" & Txtbookname2.Text & "'" Dim sborrowdate As String = "'" & Txtbrwdate.Text & "'" Dim sreturn As String = "'" & Txtrtdate.Text & "'"

'定义插入记录的SQL语句 Dim addstr As String = "insert into tblborrow (certificateID,libID,name,bookID,bookname,borrowDate,return) values (" addstr = addstr & scertificateid & "," & slibid & "," addstr = addstr & sname & "," & sbookid & "," addstr = addstr & sbookname & "," & sborrowdate & "," addstr = addstr & sreturn & ")"

'' MessageBox.Show(addstr) '打开连接 OleDbConnection2.Open() '设置InsertCommand需要执行的SQL语句 ODAcmd3.InsertCommand.CommandText = addstr '执行插入 ODAcmd3.InsertCommand.ExecuteNonQuery() '清空数据集 Ds2.Clear() '重新从数据库获取最新记录来填充数据集 ODAcmd3.Fill(Ds2) '显示最后一个记录,也就是刚刚添加的记录 Me.BindingContext(Ds2, "tblborrow").Position = Me.BindingContext(Ds2, "tblborrow").Count '关闭连接 OleDbConnection2.Close()

Dim upamount As String = "update tblbook set amount=amount-1 where bookID='" & Trim(Txtbookid2.Text) & "'" '打开连接,并执行查询 OleDbConnection2.Open() ODAcmd2.SelectCommand.CommandText = upamount ODAcmd2.SelectCommand.ExecuteNonQuery() '重新填充数据集,并关闭连接 Ds.Clear() ODAcmd2.Fill(Ds, "tblbook") OleDbConnection2.Close() Else '如果多于0条 MessageBox.Show("对不起,你所要借的书已经全部借出,请过几天再来看看.", "无法借阅-确认", MessageBoxButtons.OK) Txtbrwdate.Text = "" '清空还书日期 Txtrtdate.Text = "" TxtshlID.Text = "" TxtlibID.Text = "" Txtname.Text = "" Txtbookid2.Text = "" Txtbookname2.Text = " '显示单击“添加”按钮前显示的记录 Me.BindingContext(Ds2, "tblborrow").Position = currentPos

End If

Else '如果用户在弹出警告框时单击“取消”按钮 '重新填充数据集 'Ds2.Clear() 'ODAcmd3.Fill(Ds2) '清空借阅日期 Txtbrwdate.Text = "" '清空还书日期 Txtrtdate.Text = "" '显示单击“添加”按钮前显示的记录 Me.BindingContext(Ds2, "tblborrow").Position = currentPos End If '确认后,不管是取消还是确定,都恢复到单击“添加”按钮前的状态 ShowPosition() '显示记录的位置信息 Btbrw.Text = "借书" '按钮又恢复成“添加” Btreturn.Enabled = True '“还书”按钮可用 setall(True) '文本框只读,不相关按钮可用 Return End If

'如果是“借书”按钮,即第一次单击该按钮 If Btbrw.Text = "借书" Then '文本框置空 TxtshlID.Text = "" TxtlibID.Text = "" Txtname.Text = "" Txtbookid2.Text = "" Txtbookname2.Text = "" Txtrtdate.Text = "未还" '申请号获取当前日期 Dim t As Date = Date.Now Dim s As String = t.Date Txtbrwdate.Text = s

'改变为确认按钮 Btbrw.Text = "确认" Btreturn.Enabled = False '文本框可写,并且不相关的按钮不可用 setall(False) '结束该过程 Return End If

End Sub

搜索更多相关主题的帖子: 大侠 代码 
2005-05-19 14:55
快速回复:[求助] 哪位大侠可以帮帮小弟我看看这段代码哪里出问题啊??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016445 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved