学生管理信息系统之实时错误“91”经典问题



第一个错误

变量未定义或未找到数据成员

 

出现这种错误是因为DTPpicker这个控件后只能出现Value属性。而我在代码里输入的是Text属性,,所以会报错,只要改为Value 属性就没事了。

指示分配给 Field、Parameter 或 Property 对象的值。

 

设置和返回值

设置或返回 Variant 值,用于指示对象的值。默认值取决于 Type 属性。

 

说明

用 Value 属性设置或返回 Field 对象中的数据,与 Parameter 对象一起使用来设置或返回参数值,或者与 Property 对象一起使用来设置或返回属性设置。Value 属性为读/写还是只读取决于很多因素。关

 

ADO 允许用 Value 属性设置和返回长二进制数据

 

第二个错误

编译错误,参数不可选

Private Sub cmdDelete_Click()

     '记录下当前记录位置

mybookmark = mrc.Bookmark

     '提示是否删除

     str2$ = MsgBox("是否删除当前记录?", vbOKCancel, "删除当前记录")

     '判断按钮类型

    If Str$ = vbOK Then

Private Sub cmdDelete_Click()
     '记录下当前记录位置
     mybookmark = mrc.Bookmark
     '提示是否删除
     str2$ = MsgBox("是否删除当前记录?", vbOKCancel, "删除当前记录")
     '判断按钮类型
     If Str$ = vbOK Then

If Str$ = vbOK Then这里报错,查了str$的意思他表示返回的是字符串型变量 String, 仔细一看是少了个2

解决方法:加一个2就可以。

 

 

第三个错误

end if没有块if

 

 

 

 

代码如下:

Private Sub cmdInquire_Click()
 Dim txtSQL As String 
Dim MsgText As String 
Dim dd(4) As Boolean Dim mrc As ADODB.Recordset '组合SQL语句 
txtSQL = "select*from student_info where" '判断是否选择学号查询方式 
If Check1(0).Value Then 
If Trim(txtSID.Text) = "" Then 
smeg = "学号不能为空" MsgBox smeg, vbOKOnly + vbExclamation, "警告" txtSID.SetFocus Exit Sub Else '判断输入学号是否为数字 
If Not IsNumeric(Trim(txtSID.Text)) Then 
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告" 
Exit Sub 

txtSID.SetFocus End If dd(0) = True txtSQL = txtSQL & "student_ID'" & Trim(txtSID.Text) '结合查询语句 
End If 
End If 

If Check1(1).Value Then '判断是否选择姓名查询方式 
If Trim(txtName.Text) = "" Then smeg = "姓名不能为空" 
MsgBox smeg, vbOKOnly+vbExclamation, "警告" 
txtName.SetFocus 
Exit Sub 
Exit Sub 
Else dd(1) = True If dd(0) Then 
txtSQL = txtSQL & "and student_Name = '" & txtName.Text & "'" '结合查询语句 Else 
txtSQL = txtSQL & "stdent_name = '" & txtName.Text & "'"
 End If 
End If
 End If 
If Check1(2).Value Then ' 判断是否选择班号查询方式 

If Trim(txtClassno.Text) = "" Then ' 判断是否输入班号 smeg = "班号不能为空"
 MsgBox smeg,vbOKOnly+vbExclamation, "警告" 
txtClassno.SetFocus 
Exit Sub 
Else 
dd(2) = True If dd(0) Or dd(1) Then txtSQL = txtSQL & "and class_No = '" & txtClassno.Text & "'" 
Else 
txtSQL = txtSQL & "class_No = '" & txtClassno.Text & "'" 
End If 
End If 
End If 
If Not (dd(0) Or dd(2) Or (3)) Then '判断是否设置查询方式
 MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告" 
Exit Sub 
End If 
txtSQL = txtSQL & "order by student_ID " '查询所有满足条件的内容 
Set mrc = ExecuteSQL(txtSQL, MsgText) ' 执行查询语句 
With myFlexgrid '将查询内容显示在表格控件中 
.Rows = 2 
.CellAlignment = 4 
.TextMatrix(1, 0) = "学号" 
.TextMatrix(1, 1) = "姓名" 
.TextMatrix(1, 2) = "性别" 
.TextMatrix(1, 3) = "出生日期" 
.TextMatrix(1, 4) = "班号"
 .TextMatrix(1, 5) = "联系电话" 
.TextMatrix(1, 6) = "入校日期" 
.TextMatrix(1, 7) = "家庭住址"
 Do While Not mrc.EOF ' 判断是否移动到数据集对象的最后一条记录 
.Rows = Rows + 1 
.CellAlignment = 4 
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0) 
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2) 
.TextMatrix(.Rows - 1, 3) = Format(mrc.Fields(3), "yyyy-mm-dd") 
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4) 
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5) 
.TextMatrix(.Rows - 1, 6) = Format(mrc.Fields(6), "yyyy-mm-dd") 
.TextMatrix(.Rows - 1, 7) = mrc.Fields(7) mrc.MoveNext ' 移动到下一条记录
 Loop 
End With 
mrc.Close
 End If
 End Sub

 

解决方法:原因是在代码里多输了一个end  if  ,将end if  删除就解决了。

 

第四个错误  实时错误91

出现这中错误的可能性有三种

1. odbc没有配置好:

在运行程序之前没有配置ODBC数据源或者ODBC数据源配置错误,当然前提得是SQL Server执行了相关的SQL代码(学生系统中用到的student.mdb文件)。

2、代码问题,大多数情况是查询语句有问题(此类问题)

我出现的是代码的问题,在这里输的时候将代码输错,不细心犯的错。

3、数据库设置有问题:

 txtSQL = txtSQL & "order by stdent_ID " '查询所有满足条件的内容
         Set mrc = ExecuteSQL(txtSQL, MsgText) ' 执行查询语句
           If mrc.RecordCount = 0 Then   '判定是否有数据
              MsgBox "没有学籍信息,请关闭窗口!", vbOKOnly + vbExclamation, "警告"
              End If

将代student改对就可以了,运行起来了也没有报错了。

第五个错误

 还是实时错误  “91”

没有空格,还是一样,又犯的是代码的错,这个错误调试了好长时间,符号和空格的错误不容小觑。

运行时会在标有黄色代码这一行报错,经过好多次的调试发现是where 后有个引号,在where和引号之间没有空格。

 

 

 

Private Sub cmdInquire_Click()
    Dim txtSQL As String
    Dim MsgText As String
    Dim dd(4) As Boolean
    Dim mrc As ADODB.Recordset
    '组合SQL语句

     txtSQL = "select * from student_Info where "


所以在代码where后加一个空格就解决了,调代码一定要细心哦!

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
以下是一个简单的学生成绩管理系统的应用程序的代码实现,包含上述要求的所有功能。程序用二维数组构建学生的成绩单,实现了查询学生成绩、修改成绩、排序以及排名等功能。程序使用了简单的控制台界面,能够对错误输入进行处理,具有良好的性能和注释。 ```c++ #include <iostream> #include <string> #include <algorithm> using namespace std; // 学生信息结构体 struct Student { int id; // 学号 int scores[6]; // 成绩分数,下标对应科目编号 double totalScore; // 总成绩 int rank; // 排名 }; // 科目名称数组 string subjects[] = {"语文", "数学", "英语", "物理", "化学", "生物"}; // 学生数组,用于存储所有学生的信息 Student students[5] = { {101, {96, 79, 88, 77, 76, 83}, 499, 0}, {102, {79, 82, 86, 82, 67, 91}, 487, 0}, {103, {83, 98, 95, 92, 93, 88}, 549, 0}, {104, {92, 82, 78, 89, 81, 79}, 501, 0}, {105, {87, 95, 91, 85, 87, 75}, 520, 0} }; // 按总成绩排名比较函数,用于排序 bool compareByTotalScore(Student s1, Student s2) { return s1.totalScore > s2.totalScore; } // 查询学生某科目的平均成绩 void querySubjectScore(int subjectIndex) { double sum = 0; int n = sizeof(students) / sizeof(students[0]); for (int i = 0; i < n; i++) { sum += students[i].scores[subjectIndex]; } double avg = sum / n; cout << "所有同学的" << subjects[subjectIndex] << "平均成绩为:" << avg << endl; // 对每个学生的该科目成绩进行排序 sort(students, students + n, [](Student s1, Student s2) { return s1.scores[subjectIndex] > s2.scores[subjectIndex]; }); // 输出该生该科目的排名 for (int i = 0; i < n; i++) { if (students[i].id == subjectIndex + 101) { cout << "该生的" << subjects[subjectIndex] << "排名为:" << i + 1 << endl; break; } } } // 查询学生总成绩排名 void queryTotalScoreRank(int studentId) { int n = sizeof(students) / sizeof(students[0]); // 计算每个学生的总成绩 for (int i = 0; i < n; i++) { double sum = 0; for (int j = 0; j < 6; j++) { sum += students[i].scores[j]; } students[i].totalScore = sum; } // 对学生按总成绩排序 sort(students, students + n, compareByTotalScore); // 输出总成绩排名 for (int i = 0; i < n; i++) { if (students[i].id == studentId) { cout << "该学生的总成绩排名为:" << i + 1 << endl; break; } } // 更新每个学生的排名 for (int i = 0; i < n; i++) { students[i].rank = i + 1; } } // 修改学生某科目的成绩 void modifyScore(int studentId, int subjectIndex, int score) { int n = sizeof(students) / sizeof(students[0]); for (int i = 0; i < n; i++) { if (students[i].id == studentId) { students[i].scores[subjectIndex] = score; break; } } cout << "修改成功!" << endl; } int main() { // 输出欢迎信息和功能菜单 cout << "欢迎使用学生成绩管理系统!" << endl; cout << "请选择要执行的操作:" << endl; cout << "1. 查询学生某科目的平均成绩和排名" << endl; cout << "2. 查询学生总成绩排名" << endl; cout << "3. 修改学生某科目的成绩" << endl; cout << "请选择:"; int choice; cin >> choice; switch (choice) { case 1: // 输入学号和科目名称,查询学生成绩 int studentId, subjectIndex; cout << "请输入学号和科目名称(如语文、数学等):" << endl; cin >> studentId; cin >> subjectIndex; subjectIndex = find(subjects, subjects + 6, subjectIndex) - subjects; if (subjectIndex >= 0 && subjectIndex < 6) { querySubjectScore(subjectIndex); } else { cout << "输入错误!" << endl; } break; case 2: // 输入学号,查询总成绩排名 cout << "请输入学号:" << endl; cin >> studentId; queryTotalScoreRank(studentId); break; case 3: // 输入学号、科目名称、修改的成绩分数对成绩单中成绩进行修改 int newScore; cout << "请输入学号、科目名称和修改后的成绩分数:" << endl; cin >> studentId; cin >> subjectIndex; subjectIndex = find(subjects, subjects + 6, subjectIndex) - subjects; if (subjectIndex >= 0 && subjectIndex < 6) { cin >> newScore; modifyScore(studentId, subjectIndex, newScore); } else { cout << "输入错误!" << endl; } break; default: cout << "输入错误!" << endl; break; } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值