第一,添加一个基于CRecordSet的类为CMyRecordset1,设置如下图片。
第二,读图片文件,写入blob字段
CDatabase db;
// db.Open(NULL, FALSE, FALSE, "ODBC;DSN=kdmysql;UID=root;PWD=111");
db.Open(NULL,FALSE,FALSE,"ODBC;DSN=kdmysql;UID=root;PWD=111");
CMyRecordset1 db_set(&db);
CString sSql;
sSql = "SELECT * FROM studentphoto";
db_set.Open(CRecordset::snapshot,sSql);
db_set.AddNew();
// db.ExecuteSQL("insert into studentphoto VALUES('2017117161823704','6410020001',NULL)");
// db_set.Update();
db_set.m_testflag= "2017117161823705";
db_set.m_ExamineeID= "2017117161823705";
CFile file1;
file1.Open("E:\\practice\\TestODBC\\Debug\\6410020001.jpg",CFile::modeRead|CFile::typeBinary);//打开指定文件
db_set.m_photo.m_dwDataLength = file1.GetLength();//m_blobfile为数据库中blob字段由classwizard映射过来