现在手里有个项目,是vc6.0开发的一个winform窗体软件,需要实现一个功能:
单击一个按钮,能够实现通过网址或者IP地址连接到一个远程服务器上,服务器上有数据库(oracle或者sql server),在连接到服务器后能够读取出它的数据库上的一些表里的内容,然后再把这些数据显示在本winform窗体上。
要求:连接远程服务器并读取出数据库的操作都在后台进行,不要弹出浏览器,简单说就是只要单击下窗体上的按钮就可以把远程服务器上数据库里的某个表中的数据提取出来并显示。
大家来帮帮我吧,如果能够实现的话将有重谢(现金答谢)!
也可以联系我QQ:260885424或MSN:[email protected]
单击一个按钮,能够实现通过网址或者IP地址连接到一个远程服务器上,服务器上有数据库(oracle或者sql server),在连接到服务器后能够读取出它的数据库上的一些表里的内容,然后再把这些数据显示在本winform窗体上。
要求:连接远程服务器并读取出数据库的操作都在后台进行,不要弹出浏览器,简单说就是只要单击下窗体上的按钮就可以把远程服务器上数据库里的某个表中的数据提取出来并显示。
大家来帮帮我吧,如果能够实现的话将有重谢(现金答谢)!
也可以联系我QQ:260885424或MSN:[email protected]
解决方案 »
- 无法打开d3d9.lib,好心的前辈帮帮我吧
- oleaut32.dll 出现 access violation reading location 0xffffffff的 错误
- dll连接网络的问题
- CDialog里 怎么捕捉windows +d 事件?
- 问个问题:在网页里面嵌入activeX时,activeX没法显示?
- (急)新添加的一般类导致程序无法编译通过,请帮忙解决?
- 关于CDialogBar的隐藏问题?
- 高手请推荐几本书,关于读串口的
- CopyFile()中使用相对路径的问题
- 帮我看看聚合的问题!!!!!!
- MFC下简单的内存分配大于实际分配的内存,是何原因
- 远程连接数据库的棘手问题!
怎么没人回答啊?这个问题很难吗?
代码如下:请高手帮忙分析下
void CADOdatabaseDlg::OnInitADOConn(CString strsjk)
{
::CoInitialize(NULL);
CString strname;
//192.168.0.116是我的电脑即服务器的IP地址
//Information为要连接的表
strname.Format("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;InitialCatalog=Information;Data Source=192.168.0.116");
try
{
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect=strname;
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
这段代码在我电脑上是成功的,为什么别人电脑上不成功呢?
//For Standard Security:
strConnection = _T("Driver={SQL Server};Server=MyServerName;Trusted_Connection=no;"
"Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");
//For Trusted Connection security: (Microsoft Windows NT integrated security)
strConnection = _T("Driver={SQL Server};Server=MyServerName;Database=myDatabaseName;Uid=;Pwd=;");
//Also you can use the parameter Trusted_Connection that indicates that you are using the Microsoft Windows NT Authentication Mode to authorize user access to the SQL Server database. For example: strConnection = _T("Driver={SQL Server};Server=MyServerName;Database=MyDatabaseName;"
"Trusted_Connection=yes;");
//If the Sql Server is running in the same computer you can replace the name of the server by the word (local) like in the following sample: strConnection = _T("Driver={SQL Server};Server=(local);"
"Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");
//以下为连接SQL SERVER2005数据库,datasource的地方输入IP
//不过好像2005和2000的连接语句有点不同,你上网查查,2000的多的很
//=======================================================//
1.在工程的Cxx.cpp(在A工程中的CAApp类中)的InitInstance()函数中
/*********初始化COM库***************/
在MFC中可以用AfxOleInit();
非MFC环境中用:
CoInitialize(NULL);
CoUnInitialize();
2.在StdAfx.h中
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
3.为程序添加数据库连接函数OnInitADOConn(),函数名可以任取
void CDataConDlg::OnInitADOConn()
{
/***********连接数据库**************/
try
{
m_pConnection.CreateInstance("ADODB.Connection");
/*****************Catalog为你的数据库的名称**********************************/
CString strConnect="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=FXL;Data Source=.;";
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
/************数据库连接成功********************/}
4.需要操作数据库时:
a.添加成员变量
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
b.建立连接,创建记录集
OnInitADOConn();
//UpdateData(true);
_bstr_t sql;
sql="select * from FXL_YG";//FXL_YG为数据库中的表名
m_pRecordset.CreateInstance(_uuidof(Recordset));
m_pRecordset->Open(sql,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
c.进行你需要的操作(本例是为数据库添加一条新的记录)
try
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("编号",(_bstr_t)number);
m_pRecordset->PutCollect("姓名",(_bstr_t)name);
m_pRecordset->PutCollect("学历",(_bstr_t)culture);
m_pRecordset->Update();
}
catch(_com_error e)
{
AfxMessageBox("编号重复");
return;
}
d.关闭记录集和连接
m_pRecordset->Close();
m_pConnection->Close();
CoUninitialize();//关闭com
http://topic.csdn.net/u/20081020/21/77cd5b6b-4717-4496-b028-415989e73a71.html
就这样吧,结贴了