MFC数据库编程源代码
要求:1、先把本地一张位图显示到对话框的picture控件上再把图片读入数据库2、从数据库里面把位图读出来放到对话框的picture控件上面工具、技术及开发平台:VC6....
要求:
1、先把本地一张位图显示到对话框的picture控件上 再把图片读入数据库
2、从数据库里面把位图读出来 放到对话框的picture控件上面
工具、技术及开发平台:
VC6.0 SQL Server 2000 ado
分不是问题,符合要求追加!!!
邮箱:gqhstudy@163.com 展开
1、先把本地一张位图显示到对话框的picture控件上 再把图片读入数据库
2、从数据库里面把位图读出来 放到对话框的picture控件上面
工具、技术及开发平台:
VC6.0 SQL Server 2000 ado
分不是问题,符合要求追加!!!
邮箱:gqhstudy@163.com 展开
3个回答
展开全部
10.Sql Server7.0/2000数据库
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL); // 初始化OLE/COM库环境 ,为访问ADO接口做准备
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
_bstr_t bstrSQL("select * from stu_info"); //查询语句
char * query_cmd = "DELETE FROM stu_info WHERE sname = ’本拉登’";
try
{
// 创建Connection对象
m_pConnection.CreateInstance("ADODB.Connection");
// 设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect= "Provider=SQLOLEDB;Server=(local);Database=db2; uid=; pwd=;";
//若数据库在网络上则Server为形如(192.168.1.5,3340)
//用户sa和密码123只是针对我的库
m_pConnection->Open(strConnect,"","",adModeUnknown);
if(m_pConnection==NULL)
cerr<<"Lind data ERROR!\n";
// 创建记录集对象
m_pRecordset.CreateInstance(_uuidof(Recordset));
// 取得表中的记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t vsnum,vsname,vsage,vssex,vsmajor; //对应库中的snum,sname,sage,ssex,smajor
cout << "学号 姓名 年龄 姓别 专业";
cout << "\n----------------------------------------------------------------\n";
while (!m_pRecordset->EndOfFile)
{
vsnum = m_pRecordset->GetCollect(_variant_t((long)0));//这儿给字段编号和字段名都可以
vsname = m_pRecordset->GetCollect("sname");
vsage = m_pRecordset->GetCollect("sage");
vssex = m_pRecordset->GetCollect("ssex");
vsmajor = m_pRecordset->GetCollect("smajor");
if (vsnum.vt != VT_NULL && vsname.vt != VT_NULL && vsage.vt != VT_NULL
&& vssex.vt != VT_NULL && vsmajor.vt != VT_NULL)
{
cout.setf(ios::left);
cout << setw(14) << (char*)(_bstr_t)vsnum;
cout << setw(14) << (char*)(_bstr_t)vsname;
cout << setw(8) << vsage.lVal;
cout << setw(8) << (char*)(_bstr_t)vssex;
cout <<setw(20) << (char*)(_bstr_t)vsmajor;
cout.unsetf(ios::left);
cout << endl;
}
m_pRecordset->MoveNext(); ///移到下一条记录
}
cout << "\n----------------------------------------------------------------\n";
cout << "\n请输入你要添加的学生信息\n";
cout << "学号:";
cin >> student.snum;
cout << "\n姓名:";
cin >> student.sname;
cout << "\n年龄:";
cin >> student.sage;
cout << "\n姓别:";
cin >> student.ssex;
cout << "\n专业:";
cin >> student.smajor;
m_pRecordset->MoveFirst(); //移动到第一条记录
m_pRecordset->AddNew(); ///添加新记录
m_pRecordset->PutCollect("snum",_variant_t(student.snum));
m_pRecordset->PutCollect("sname",_variant_t(student.sname));
m_pRecordset->PutCollect("sage",_variant_t(student.sage));
m_pRecordset->PutCollect("ssex",_variant_t(student.ssex));
m_pRecordset->PutCollect("smajor",_variant_t(student.smajor));
m_pRecordset->Update();
m_pConnection->Execute(query_cmd,NULL,1); //用Execute执行sql语句来删除
m_pRecordset->Close(); // 关闭记录集
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
cerr << "\nERROR:" << (char*)e.Description();//抛出异常
}
if(m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
20.数据库存入二进制字段数据
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL);
_RecordsetPtr pRs=NULL;
_StreamPtr pStream=NULL;
pRs.CreateInstance(_uuidof(Recordset));
pStream.CreateInstance(__unidof(Stream));
_bstr_t ConnectString(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%1;Persist Security Info=False"); //C:\\mydb.mdb
pRs->Open(_bstr_t("Blob"),ConnectString,adOpenKeyset,adLockOptimistic,adCmdTable);
_variant vtSource;
vtSource.vt=VT_ERROR;
_bstr_t bstrUser(L"");
_bstr_t bstrPass(L"");
pStream->Type=adTypeBinary;
pStream->Open(vtSource,adModeUnknown,adOpenStreamUnspecified,bstrUser,bstrPass);
pStream->LoadFromFile(_bstr_t(%%3)); //"C:\\mypic.bmp"
pRs->AddNew();
pRs->Fields->GetItem(_variant_t(%%2))->put_Value(_variant_t(pStream->Read(adReadAll))); //"Image"
pRs->();
pStream->Close();
pRs->Close();
CoUninitialize();
21.数据库取出二进制字段数据
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL);
_RecordsetPtr pRs=NULL;
_StreamPtr pStream=NULL;
pRs.CreateInstance(_uuidof(Recordset));
pStream.CreateInstance(__unidof(Stream));
_bstr_t ConnectString(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%1;Persist Security Info=False");//C:\\mydb.mdb
pRs->Open(_bstr_t("Blob"),ConnectString,adOpenKeyset,adLockOptimistic,adCmdTable);
pStream->Write(_variant_t(pRs->Fields->GetItem(_variant_t(%%2))->GetValue())); //"Image"
pStream->SaveToFile(_bstr_t(%%3),adSaveCreateOverWrite); //"C:\\mypic.bmp"
pStream->Close();
pRs->Close();
CoUninitialize();
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL); // 初始化OLE/COM库环境 ,为访问ADO接口做准备
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
_bstr_t bstrSQL("select * from stu_info"); //查询语句
char * query_cmd = "DELETE FROM stu_info WHERE sname = ’本拉登’";
try
{
// 创建Connection对象
m_pConnection.CreateInstance("ADODB.Connection");
// 设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect= "Provider=SQLOLEDB;Server=(local);Database=db2; uid=; pwd=;";
//若数据库在网络上则Server为形如(192.168.1.5,3340)
//用户sa和密码123只是针对我的库
m_pConnection->Open(strConnect,"","",adModeUnknown);
if(m_pConnection==NULL)
cerr<<"Lind data ERROR!\n";
// 创建记录集对象
m_pRecordset.CreateInstance(_uuidof(Recordset));
// 取得表中的记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t vsnum,vsname,vsage,vssex,vsmajor; //对应库中的snum,sname,sage,ssex,smajor
cout << "学号 姓名 年龄 姓别 专业";
cout << "\n----------------------------------------------------------------\n";
while (!m_pRecordset->EndOfFile)
{
vsnum = m_pRecordset->GetCollect(_variant_t((long)0));//这儿给字段编号和字段名都可以
vsname = m_pRecordset->GetCollect("sname");
vsage = m_pRecordset->GetCollect("sage");
vssex = m_pRecordset->GetCollect("ssex");
vsmajor = m_pRecordset->GetCollect("smajor");
if (vsnum.vt != VT_NULL && vsname.vt != VT_NULL && vsage.vt != VT_NULL
&& vssex.vt != VT_NULL && vsmajor.vt != VT_NULL)
{
cout.setf(ios::left);
cout << setw(14) << (char*)(_bstr_t)vsnum;
cout << setw(14) << (char*)(_bstr_t)vsname;
cout << setw(8) << vsage.lVal;
cout << setw(8) << (char*)(_bstr_t)vssex;
cout <<setw(20) << (char*)(_bstr_t)vsmajor;
cout.unsetf(ios::left);
cout << endl;
}
m_pRecordset->MoveNext(); ///移到下一条记录
}
cout << "\n----------------------------------------------------------------\n";
cout << "\n请输入你要添加的学生信息\n";
cout << "学号:";
cin >> student.snum;
cout << "\n姓名:";
cin >> student.sname;
cout << "\n年龄:";
cin >> student.sage;
cout << "\n姓别:";
cin >> student.ssex;
cout << "\n专业:";
cin >> student.smajor;
m_pRecordset->MoveFirst(); //移动到第一条记录
m_pRecordset->AddNew(); ///添加新记录
m_pRecordset->PutCollect("snum",_variant_t(student.snum));
m_pRecordset->PutCollect("sname",_variant_t(student.sname));
m_pRecordset->PutCollect("sage",_variant_t(student.sage));
m_pRecordset->PutCollect("ssex",_variant_t(student.ssex));
m_pRecordset->PutCollect("smajor",_variant_t(student.smajor));
m_pRecordset->Update();
m_pConnection->Execute(query_cmd,NULL,1); //用Execute执行sql语句来删除
m_pRecordset->Close(); // 关闭记录集
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
cerr << "\nERROR:" << (char*)e.Description();//抛出异常
}
if(m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
20.数据库存入二进制字段数据
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL);
_RecordsetPtr pRs=NULL;
_StreamPtr pStream=NULL;
pRs.CreateInstance(_uuidof(Recordset));
pStream.CreateInstance(__unidof(Stream));
_bstr_t ConnectString(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%1;Persist Security Info=False"); //C:\\mydb.mdb
pRs->Open(_bstr_t("Blob"),ConnectString,adOpenKeyset,adLockOptimistic,adCmdTable);
_variant vtSource;
vtSource.vt=VT_ERROR;
_bstr_t bstrUser(L"");
_bstr_t bstrPass(L"");
pStream->Type=adTypeBinary;
pStream->Open(vtSource,adModeUnknown,adOpenStreamUnspecified,bstrUser,bstrPass);
pStream->LoadFromFile(_bstr_t(%%3)); //"C:\\mypic.bmp"
pRs->AddNew();
pRs->Fields->GetItem(_variant_t(%%2))->put_Value(_variant_t(pStream->Read(adReadAll))); //"Image"
pRs->();
pStream->Close();
pRs->Close();
CoUninitialize();
21.数据库取出二进制字段数据
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL);
_RecordsetPtr pRs=NULL;
_StreamPtr pStream=NULL;
pRs.CreateInstance(_uuidof(Recordset));
pStream.CreateInstance(__unidof(Stream));
_bstr_t ConnectString(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%1;Persist Security Info=False");//C:\\mydb.mdb
pRs->Open(_bstr_t("Blob"),ConnectString,adOpenKeyset,adLockOptimistic,adCmdTable);
pStream->Write(_variant_t(pRs->Fields->GetItem(_variant_t(%%2))->GetValue())); //"Image"
pStream->SaveToFile(_bstr_t(%%3),adSaveCreateOverWrite); //"C:\\mypic.bmp"
pStream->Close();
pRs->Close();
CoUninitialize();
展开全部
MFC提供了对数据库编程的强大支持。对于数据库的访问,MFC提供了两组类:ODBC(Open Database Connectivity)和DAO(Database Access Object)。利用这两个功能强大的类,用户可以方便的开发出基于ODBC或DAO的数据库应用。
这一讲将重点介绍下列内容:
数据库的基本概念
ODBC基本概念
MFC的ODBC类简介
CDatabase类
CRecordset类
CRecordView类
用AppWizard和ClassWizard编写Enroll数据库应用例程
DAO和DAO类
自动注册DSN和创建表
小结
参考资料:http://hi.baidu.com/ypxmaomao/blog/item/5365d2ec7984c43a27979115.html
这一讲将重点介绍下列内容:
数据库的基本概念
ODBC基本概念
MFC的ODBC类简介
CDatabase类
CRecordset类
CRecordView类
用AppWizard和ClassWizard编写Enroll数据库应用例程
DAO和DAO类
自动注册DSN和创建表
小结
参考资料:http://hi.baidu.com/ypxmaomao/blog/item/5365d2ec7984c43a27979115.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可惜我机器没配置。10月1回家帮你弄。so easy!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询