vb修改数据库数据 30
为什么修改数据后就把没想修改的数据也覆盖了呢?找了半天也找不出原因,以下是程序PrivateSubCommand2_Click()DimiAsInteger,s1AsSt...
为什么修改数据后就把没想修改的数据也覆盖了呢?找了半天也找不出原因,以下是程序
Private Sub Command2_Click()
Dim i As Integer, s1 As String, s2 As String
Dim RS As Recordset
Dim aa As Integer
'DBGrid1.Refresh
Data1.Refresh
If Data1.Recordset.RecordCount > 0 Then
Data1.Recordset.MoveFirst
'If Not Data1.Recordset.EOF Then
Do While Not Data1.Recordset.EOF
If Trim(Str(DBGrid1.Columns(0))) = "" Then
MsgBox "学号不能为空!", vbCritical, "输入错误"
DBGrid1.SetFocus
Exit Sub
ElseIf Len(Trim(DBGrid1.Columns(0))) < 10 Then
MsgBox "学号位数不足10位!", vbCritical, "输入错误"
DBGrid1.SetFocus
Exit Sub
End If
For i = 1 To total_ti
If Trim(DBGrid1.Columns(i)) = "" Or Val(Trim(DBGrid1.Columns(i))) > fen(i - 1) Then
MsgBox "得分不能超过本大题分值范围:0 ~ " + Str(fen(i - 1)), vbCritical, "输入错误"
DBGrid1.SetFocus
'DBGrid1.Column(1).SetFocus
'DBGrid1.Columns [2].getfocus
Exit Sub
End If
Next i
Data1.Recordset.MoveNext
Loop
aa = MsgBox("要结束修改吗?", vbOKCancel, "确认")
If aa = 1 Then
Set RS = DB.OpenRecordset("select * from stu_cj ")
Data1.Recordset.MoveFirst
Do While Not Data1.Recordset.EOF
For i = 1 To 10
If Trim(DBGrid1.Columns(i)) = "" Then
DBGrid1.Columns(i) = "0"
End If
Next i
RS.AddNew
RS!SJID = SJID
RS!SID = DBGrid1.Columns(0)
RS!T1 = Val(Trim(DBGrid1.Columns(1)))
RS!T2 = Val(Trim(DBGrid1.Columns(2)))
RS!T3 = Val(Trim(DBGrid1.Columns(3)))
RS!T4 = Val(Trim(DBGrid1.Columns(4)))
RS!T5 = Val(Trim(DBGrid1.Columns(5)))
RS!T6 = Val(Trim(DBGrid1.Columns(6)))
RS!T7 = Val(Trim(DBGrid1.Columns(7)))
RS!T8 = Val(Trim(DBGrid1.Columns(8)))
RS!T9 = Val(Trim(DBGrid1.Columns(9)))
RS!T10 = Val(Trim(DBGrid1.Columns(10)))
RS.Update
Data1.Recordset.MoveNext
Loop
Unload Me
End If
Else
MsgBox "您没有输入任何数据,请输入!", vbCritical, "输入错误"
End If
End Sub
能不能详细一下说说~ 展开
Private Sub Command2_Click()
Dim i As Integer, s1 As String, s2 As String
Dim RS As Recordset
Dim aa As Integer
'DBGrid1.Refresh
Data1.Refresh
If Data1.Recordset.RecordCount > 0 Then
Data1.Recordset.MoveFirst
'If Not Data1.Recordset.EOF Then
Do While Not Data1.Recordset.EOF
If Trim(Str(DBGrid1.Columns(0))) = "" Then
MsgBox "学号不能为空!", vbCritical, "输入错误"
DBGrid1.SetFocus
Exit Sub
ElseIf Len(Trim(DBGrid1.Columns(0))) < 10 Then
MsgBox "学号位数不足10位!", vbCritical, "输入错误"
DBGrid1.SetFocus
Exit Sub
End If
For i = 1 To total_ti
If Trim(DBGrid1.Columns(i)) = "" Or Val(Trim(DBGrid1.Columns(i))) > fen(i - 1) Then
MsgBox "得分不能超过本大题分值范围:0 ~ " + Str(fen(i - 1)), vbCritical, "输入错误"
DBGrid1.SetFocus
'DBGrid1.Column(1).SetFocus
'DBGrid1.Columns [2].getfocus
Exit Sub
End If
Next i
Data1.Recordset.MoveNext
Loop
aa = MsgBox("要结束修改吗?", vbOKCancel, "确认")
If aa = 1 Then
Set RS = DB.OpenRecordset("select * from stu_cj ")
Data1.Recordset.MoveFirst
Do While Not Data1.Recordset.EOF
For i = 1 To 10
If Trim(DBGrid1.Columns(i)) = "" Then
DBGrid1.Columns(i) = "0"
End If
Next i
RS.AddNew
RS!SJID = SJID
RS!SID = DBGrid1.Columns(0)
RS!T1 = Val(Trim(DBGrid1.Columns(1)))
RS!T2 = Val(Trim(DBGrid1.Columns(2)))
RS!T3 = Val(Trim(DBGrid1.Columns(3)))
RS!T4 = Val(Trim(DBGrid1.Columns(4)))
RS!T5 = Val(Trim(DBGrid1.Columns(5)))
RS!T6 = Val(Trim(DBGrid1.Columns(6)))
RS!T7 = Val(Trim(DBGrid1.Columns(7)))
RS!T8 = Val(Trim(DBGrid1.Columns(8)))
RS!T9 = Val(Trim(DBGrid1.Columns(9)))
RS!T10 = Val(Trim(DBGrid1.Columns(10)))
RS.Update
Data1.Recordset.MoveNext
Loop
Unload Me
End If
Else
MsgBox "您没有输入任何数据,请输入!", vbCritical, "输入错误"
End If
End Sub
能不能详细一下说说~ 展开
展开全部
真是没有设条件。
两种方法
1 在SET RS时加上WHERE 学号字段名=学号
2 先用RS 取到所有记录
再用RS.Filter="学号字段名=学号"
当然都要测试一下RS.RecordCount是否大于零不判断是否找到记录
两种方法
1 在SET RS时加上WHERE 学号字段名=学号
2 先用RS 取到所有记录
再用RS.Filter="学号字段名=学号"
当然都要测试一下RS.RecordCount是否大于零不判断是否找到记录
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Set RS = DB.OpenRecordset("select * from stu_cj ")
加where条件
Set RS = DB.OpenRecordset("select * from stu_cj where SID = DBGrid1.Columns(0))
加where条件
Set RS = DB.OpenRecordset("select * from stu_cj where SID = DBGrid1.Columns(0))
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要设置条件啊,用FOR OR WHILE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Set RS = DB.OpenRecordset("select * from stu_cj ")
加where条件
Set RS = DB.OpenRecordset("select * from stu_cj where ID = 1")
加where条件
Set RS = DB.OpenRecordset("select * from stu_cj where ID = 1")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询