MySQL数据库程序错误

博主在做作业时遇到一个困扰的问题,涉及一个修改学生信息的MySQL语句出现错误,提示语句不规范。代码已给出,但未能成功执行,导致程序无法正常更改信息。
摘要由CSDN通过智能技术生成

是我太菜了吗,这个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;
			cout << "============&#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值