📄 subject_27312.htm
字号:
<p>
序号:27312 发表者:我就是要学VC 发表日期:2003-01-10 10:55:55
<br>主题:vc 与 ms sql2000如何组合啊?语言方面!
<br>内容:现在用vc作界面,用sql2000数据库,二者组合在一起.<BR>想请问一下:如何将数据库的查询语言嵌套在vc中??<BR>Crecordset吗?请问如何结合?用什么语句结合?请具体的讲一讲!!<BR>谢谢!!<BR><BR>另:当点击对话框或菜单上的某个按钮后,要求弹出一个对话框(不是messagebox),请问如何实现?用什么语句?<BR>那位大虾有什么实例,给上传参考一下!!<BR>谢谢了!!!!!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:michael 回复日期:2003-01-10 12:19:43
<br>内容: 用OLE DB或者ADO连SQL SERVER OLE DB是基于COM的一套模板库 ADO是一套COM组件。<BR>ADO请参阅徐景周写的一个例程在咱们站上的“最新更新”里有。我这有一个俄罗斯人写的OLE DB例程。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:ax 回复日期:2003-01-10 12:20:21
<br>内容:使用Ado,Ado是Com组件,可以使用_ConnectionPtr连接数据库,_RecordsetPtr打开记录集,具体使用方式如下,也可以参照Msdn.<BR><BR>#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \<BR> no_namespace rename("EOF", "EndOfFile")<BR><BR>#include <oledb.h><BR>#include <stdio.h><BR>#include <conio.h><BR>#include "OpenX.h"<BR><BR>// Function declarations<BR>inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};<BR>void OpenX(void);<BR>void PrintProviderError(_ConnectionPtr pConnection);<BR>void PrintComError(_com_error &e);<BR><BR>///////////////////////////////////////////////////////////<BR>// //<BR>// Main Function //<BR>// //<BR>///////////////////////////////////////////////////////////<BR><BR>void main()<BR>{<BR> if(FAILED(::CoInitialize(NULL)))<BR> return;<BR><BR> OpenX();<BR><BR> ::CoUninitialize();<BR>}<BR><BR>///////////////////////////////////////////////////////////<BR>// //<BR>// OpenX Function //<BR>// //<BR>///////////////////////////////////////////////////////////<BR><BR>void OpenX(void)<BR>{<BR> // Define ADO object pointers.<BR> // Initialize pointers on define.<BR> // These are in the ADODB:: namespace<BR> _RecordsetPtr pRstEmployee = NULL;<BR> _ConnectionPtr pConnection = NULL;<BR><BR> // Define string variables.<BR> _bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"<BR> "Initial Catalog=pubs;User Id=sa;Password=;");<BR><BR> // Define Other Variables.<BR> HRESULT hr = S_OK;<BR> IADORecordBinding *picRs = NULL; // Interface Pointer declared.<BR> CEmployeeRs emprs; // C++ Class object<BR> DBDATE varDate;<BR><BR> try<BR> {<BR> // open connection and record set<BR> TESTHR(pConnection.CreateInstance(__uuidof(Connection)));<BR> pConnection->Open(strCnn,"","",adConnectUnspecified);<BR><BR> TESTHR(pRstEmployee.CreateInstance(__uuidof(Recordset)));<BR> pRstEmployee->Open("Employee", <BR> _variant_t((IDispatch *)pConnection,true), adOpenKeyset,<BR> adLockOptimistic, adCmdTable);<BR><BR> // Open an IADORecordBinding interface pointer which we'll <BR> // use for Binding Recordset to a class.<BR> TESTHR(pRstEmployee->QueryInterface(<BR> __uuidof(IADORecordBinding),(LPVOID*)&picRs));<BR><BR> //Bind the Recordset to a C++ Class here.<BR> TESTHR(picRs->BindToRecordset(&emprs));<BR><BR> // Assign the first employee record's hire date<BR> // to a variable, then change the hire date.<BR> varDate = emprs.m_sze_hiredate;<BR> printf("\nOriginal data\n");<BR> printf("\tName - Hire Date\n");<BR> printf(" %s %s - %d/%d/%d\n\n",<BR> emprs.le_fnameStatus == adFldOK ? <BR> emprs.m_sze_fname : "<NULL>",<BR> emprs.le_lnameStatus == adFldOK ? <BR> emprs.m_sze_lname : "<NULL>",<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.month : 0,<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.day : 0,<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.year : 0); <BR><BR> emprs.m_sze_hiredate.year=1900;<BR> emprs.m_sze_hiredate.month=1;<BR> emprs.m_sze_hiredate.day=1;<BR> picRs->Update(&emprs);<BR><BR> printf("\nChanged data\n");<BR> printf("\tName - Hire Date\n");<BR> printf(" %s %s - %d/%d/%d\n\n",<BR> emprs.le_fnameStatus == adFldOK ? <BR> emprs.m_sze_fname : "<NULL>",<BR> emprs.le_lnameStatus == adFldOK ? <BR> emprs.m_sze_lname : "<NULL>",<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.month : 0,<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.day : 0,<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.year : 0); <BR><BR> // Requery Recordset and reset the hire date.<BR> pRstEmployee->Requery(adOptionUnspecified);<BR> // Open an IADORecordBinding interface pointer which we'll <BR> // use for Binding Recordset to a class.<BR> TESTHR(pRstEmployee->QueryInterface(<BR> __uuidof(IADORecordBinding),(LPVOID*)&picRs));<BR><BR> // Rebind the Recordset to a C++ Class here.<BR> TESTHR(picRs->BindToRecordset(&emprs));<BR> emprs.m_sze_hiredate = varDate;<BR> picRs->Update(&emprs);<BR> printf("\nData after reset\n");<BR> printf("\tName - Hire Date\n");<BR> printf(" %s %s - %d/%d/%d",emprs.le_fnameStatus == adFldOK ? <BR> emprs.m_sze_fname : "<NULL>",<BR> emprs.le_lnameStatus == adFldOK ? <BR> emprs.m_sze_lname : "<NULL>",<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.month : 0,<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.day : 0,<BR> emprs.le_hiredateStatus == adFldOK ? <BR> emprs.m_sze_hiredate.year : 0); <BR><BR> // Clean up objects before exit.<BR> pRstEmployee->Close();<BR> pConnection->Close();<BR> }<BR><BR> catch(_com_error &e)<BR> {<BR> // Notify the user of errors if any.<BR> // Pass a connection pointer accessed from the Connection.<BR> PrintProviderError(pConnection);<BR> PrintComError(e);<BR> }<BR>}<BR><BR>///////////////////////////////////////////////////////////<BR>// //<BR>// PrintProviderError Function //<BR>// //<BR>///////////////////////////////////////////////////////////<BR><BR>void PrintProviderError(_ConnectionPtr pConnection)<BR>{<BR> // Print Provider Errors from Connection object.<BR> // pErr is a record object in the Connection's Error collection.<BR> ErrorPtr pErr = NULL;<BR><BR> if( (pConnection->Errors->Count) > 0)<BR> {<BR> long nCount = pConnection->Errors->Count;<BR> // Collection ranges from 0 to nCount -1.<BR> for(long i = 0;i < nCount;i++)<BR> {<BR> pErr = pConnection->Errors->GetItem(i);<BR> printf("\t Error number: %x\t%s", pErr->Number,<BR> pErr->Description);<BR> }<BR> }<BR>}<BR><BR>///////////////////////////////////////////////////////////<BR>// //<BR>// PrintComError Function //<BR>// //<BR>///////////////////////////////////////////////////////////<BR><BR>void PrintComError(_com_error &e)<BR>{<BR> _bstr_t bstrSource(e.Source());<BR> _bstr_t bstrDescription(e.Description());<BR><BR> // Print COM errors. <BR> printf("Error\n");<BR> printf("\tCode = %08lx\n", e.Error());<BR> printf("\tCode meaning = %s\n", e.ErrorMessage());<BR> printf("\tSource = %s\n", (LPCSTR) bstrSource);<BR> printf("\tDescription = %s\n", (LPCSTR) bstrDescription);<BR>}<BR>// EndOpenCpp<BR><BR>OpenX.h:<BR><BR>// BeginOpenH<BR>#include "icrsint.h"<BR><BR>// This Class extracts only fname,lastname and <BR>// hire_date from employee table<BR>class CEmployeeRs : public CADORecordBinding<BR>{<BR><BR>BEGIN_ADO_BINDING(CEmployeeRs)<BR> <BR> // Column fname is the 2nd field in the table <BR> ADO_VARIABLE_LENGTH_ENTRY2(2, adVarChar, m_sze_fname, <BR> sizeof(m_sze_fname), le_fnameStatus, FALSE)<BR> <BR> // Column lname is the 4th field in the table.<BR> ADO_VARIABLE_LENGTH_ENTRY2(4, adVarChar, m_sze_lname, <BR> sizeof(m_sze_lname), le_lnameStatus, FALSE)<BR><BR> // Column hiredate is the 8th field in the table.<BR> ADO_VARIABLE_LENGTH_ENTRY2(8, adDBDate,m_sze_hiredate, <BR> sizeof(m_sze_hiredate), le_hiredateStatus, TRUE)<BR> <BR>END_ADO_BINDING()<BR><BR>public:<BR> CHAR m_sze_fname[21];<BR> ULONG le_fnameStatus;<BR> CHAR m_sze_lname[31];<BR> ULONG le_lnameStatus;<BR> DBDATE m_sze_hiredate;<BR> ULONG le_hiredateStatus;<BR>};<BR>// EndOpenH<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bird 回复日期:2003-01-10 13:50:58
<br>内容:你的第二个问题:<BR>如果你创建好了对话框了!用YourDialog.show()
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:bird 回复日期:2003-01-10 13:56:01
<br>内容:第一个问题有篇文章可以看看:<BR>http://www.citytea.com/article/list.asp?id=299
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -