r如何在vc中用确定按钮连接sql数据库的代码及步骤 在vc里获得系统时间 和其他1些信息 往sql server 2000数据库里写怎么才能实现的代码和步骤 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 UpdateData(); HRESULT hRe; char buf[200]; _variant_t theValue;//操作数据库所必用的类型 try { connDB(); memset(buf,0,sizeof(buf)); strcpy(buf,"select pjid from PJ_DATE"); hRe=rs->Open(_variant_t(buf),pConn.GetInterfacePtr(),adOpenForwardOnly,adLockReadOnly,adCmdText); memcpy(gadpjid,(const char*)(_bstr_t)(_variant_t)rs->GetCollect("pjid").bstrVal,sizeof(gadpjid)); m_listpj.SetItemText(1,1,gadpjid); } catch(_com_error &e) { char buf[200]; memset(buf,0,200); _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription); //AddLogInfo(buf); rs->Close(); pConn->Close(); return ; }}void CSetPJDlg::connDB(){ HRESULT hRe; //定义一个用于获取返回值的句柄 char strconn[1024];//定义一个连接字符串 hRe=pConn.CreateInstance(__uuidof(Connection));//建立数据库连接实例 if(FAILED(hRe)) { AfxMessageBox("创建数据库连接失败!"); return ; } hRe=rs.CreateInstance(__uuidof(Recordset)); //建立纪录集实例 if(FAILED(hRe)) { pConn->Close(); AfxMessageBox("创建纪录集失败!"); return ; } try {HMODULE hmodule; int len; char gExename[256]; memset(gExename,0,sizeof(gExename)); hmodule=GetModuleHandle("syecc_pj.exe"); len=GetModuleFileName(hmodule,gExename,256); gExename[len-12]=0; strcat(gExename,"config.ini"); char sserver[20],sdatabase[20],suid[50],spwd[50]; memset(sserver,0,sizeof(sserver)); memset(sdatabase,0,sizeof(sdatabase)); memset(suid,0,sizeof(suid)); memset(spwd,0,sizeof(spwd)); GetPrivateProfileString("database","servername","",sserver,sizeof(sserver),gExename); GetPrivateProfileString("database","database","",sdatabase,sizeof(sdatabase),gExename); GetPrivateProfileString("database","logId","",suid,sizeof(suid),gExename); GetPrivateProfileString("database","logpass","",spwd,sizeof(spwd),gExename); sprintf(strconn,"Driver={SQL Server};Server=%s;Database=%s;Uid=%s;Pwd=%s;",sserver,sdatabase,suid,spwd);// strcpy(strconn,"Driver={SQL Server};Server=yhm;Database=pj1022;;Uid=sa;Pwd=123465;"); _bstr_t strCnn(strconn); //用数据库连接字符串初始化_bstr_t类对象strCnn hRe=pConn->Open(strCnn,suid,spwd,-1); if(FAILED(hRe)) { AfxMessageBox("连接数据库失败!"); return ; } } catch(_com_error &e) { char buf[200]; memset(buf,0,200); _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription); //AddLogInfo(buf); // rs->Close(); pConn->Close(); return ; }} C++调用matlab时 数组转换成矩阵怎么处理 哈哈哈哈哈哈哈哈散分。。。 大家帮帮忙,VC转office文档为html的方式? 求助!opengl 麻烦各位一下,把这段代码转成VC,谢谢 求P2P方面资源! XP按钮如何做啊??? 1/3 连发三贴寻求支持,我要当这里的副斑竹! 我能下载的都试验过,没有可用的JDK和tomcat!!怎么办?请各位大吓帮忙! 关于县城优先级的问题 fatal error C1083 编译错误 MSChart能否获取坐标的原点??
HRESULT hRe;
char buf[200];
_variant_t theValue;//操作数据库所必用的类型
try
{
connDB();
memset(buf,0,sizeof(buf));
strcpy(buf,"select pjid from PJ_DATE");
hRe=rs->Open(_variant_t(buf),pConn.GetInterfacePtr(),adOpenForwardOnly,adLockReadOnly,adCmdText);
memcpy(gadpjid,(const char*)(_bstr_t)(_variant_t)rs->GetCollect("pjid").bstrVal,sizeof(gadpjid));
m_listpj.SetItemText(1,1,gadpjid);
} catch(_com_error &e)
{
char buf[200];
memset(buf,0,200);
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
//AddLogInfo(buf);
rs->Close();
pConn->Close();
return ;
}
}void CSetPJDlg::connDB()
{ HRESULT hRe; //定义一个用于获取返回值的句柄
char strconn[1024];//定义一个连接字符串
hRe=pConn.CreateInstance(__uuidof(Connection));//建立数据库连接实例
if(FAILED(hRe))
{
AfxMessageBox("创建数据库连接失败!");
return ;
} hRe=rs.CreateInstance(__uuidof(Recordset)); //建立纪录集实例
if(FAILED(hRe))
{
pConn->Close();
AfxMessageBox("创建纪录集失败!");
return ;
}
try
{
HMODULE hmodule;
int len;
char gExename[256];
memset(gExename,0,sizeof(gExename));
hmodule=GetModuleHandle("syecc_pj.exe");
len=GetModuleFileName(hmodule,gExename,256);
gExename[len-12]=0;
strcat(gExename,"config.ini");
char sserver[20],sdatabase[20],suid[50],spwd[50];
memset(sserver,0,sizeof(sserver));
memset(sdatabase,0,sizeof(sdatabase));
memset(suid,0,sizeof(suid));
memset(spwd,0,sizeof(spwd)); GetPrivateProfileString("database","servername","",sserver,sizeof(sserver),gExename);
GetPrivateProfileString("database","database","",sdatabase,sizeof(sdatabase),gExename);
GetPrivateProfileString("database","logId","",suid,sizeof(suid),gExename);
GetPrivateProfileString("database","logpass","",spwd,sizeof(spwd),gExename);
sprintf(strconn,"Driver={SQL Server};Server=%s;Database=%s;Uid=%s;Pwd=%s;",sserver,sdatabase,suid,spwd);// strcpy(strconn,"Driver={SQL Server};Server=yhm;Database=pj1022;;Uid=sa;Pwd=123465;");
_bstr_t strCnn(strconn); //用数据库连接字符串初始化_bstr_t类对象strCnn
hRe=pConn->Open(strCnn,suid,spwd,-1);
if(FAILED(hRe))
{
AfxMessageBox("连接数据库失败!");
return ;
}
}
catch(_com_error &e)
{
char buf[200];
memset(buf,0,200);
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
//AddLogInfo(buf);
// rs->Close();
pConn->Close();
return ;
}
}