是我太菜了吗,这个MySQL语句我真的不知道有啥问题呀,做作业做到崩溃边缘。啊!!!!
程序里面的这个函数,修改信息的MySQL语句有错误 说是MySQL语句不规范
//添加学生信息,插入全局变量stu代表学生!
void InsertStudent()
{
sprintf(szSqlText, "insert into tbl_student(id,name,sex,age,score_cp,score_en,score_math)values('%s','%s','%s',%d,%d,%d,%d)", stu.id, stu.name, stu.sex, stu.age, stu.score.cp
, stu.score.en, stu.score.math);
if (mysql_query(conn, szSqlText))
{
cout << mysql_error(conn) << endl;
printf("inserted failed\n");
cout << endl;
}
}
嗯.....刚才又运行了一下,错误变成了这个
0x00007FFA7BBA2BE7 (ucrtbased.dll)处(位于 实战8_学生学籍管理系统.exe 中)引发的异常: 0xC0000005: 读取位置 0xFFFFFFFFFFFFFFFF 时发生访问冲突。 出现了
这里是完整代码,但是修改学生信息有问题,不能更改信息
//#define _CRT_SECURE_NO_WARINGS
#include<iostream>
#include<WinSock.h>
#include<cstdio>
#include<string>
#include<conio.h>
#include"mysql.h"
#pragma comment(lib,"wsock32.lib")
#pragma comment(lib,"libmysql.lib")
#pragma waining(disable:4990)
using namespace std;
#define IDLen 13
#define NameLen 11
#define SexLen 5
//存储学生成绩的结构体
struct Score
{
int cp;//C语言成绩
int en;//英语成绩
int math;//高数成绩
};
//存储学生信息的结构体
typedef struct Stu
{
char id[IDLen];//学号
char name[NameLen];//姓名
char sex[SexLen];//性别
int age;//年龄
struct Score score;//成绩
double avg;//平均分
}Student;
MYSQL* conn;//mysql对象
char szSqlText[1000] = "";//sql语句
char sortField[100];//用户选择的排序字段名称,以及排序方向
Student stu;//存放一个学生信息的数组
//访问MySQL数据库表tbl_student,打印输出学生的所有信息
void OutputStudent()
{
int i;
MYSQL_RES* res;
MYSQL_ROW row;
sprintf(szSqlText, "select id,name,sex,age,score_cp,score_en,score_math,(score_cp+score_en+score_math)/3 score_avg from tbl_student order by ");
strcat(szSqlText, sortField);//添加排序方式
if (mysql_query(conn, szSqlText))
{
cout<<mysql_error(conn)<<endl;
cout << "select failed." << endl;
return;
}
else
{
res = mysql_store_result(conn);
i = (int)mysql_num_rows(res);
if (i > 0)//如果有学生信息
{
cout << endl << "共有" << i << "个学生信息:" << endl;
cou