⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odbcrecordset.htm

📁 几个老外写的源代码大家快快下载
💻 HTM
📖 第 1 页 / 共 2 页
字号:
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%" bgcolor="#800000"><font color="#FFFFFF"><strong>AsLong</strong></font></td>
    <td width="10%">0</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%" bgcolor="#800000"><font color="#FFFFFF"><strong>AsFloat</strong></font></td>
    <td width="10%">0.0</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%" bgcolor="#800000"><font color="#FFFFFF"><strong>AsDouble</strong></font></td>
    <td width="10%">0.0</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%" bgcolor="#800000"><font color="#FFFFFF"><strong>AsDate</strong></font></td>
    <td width="10%">null</td>
    <td width="10%">invalid</td>
    <td width="10%">invalid</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%" bgcolor="#800000"><font color="#FFFFFF"><strong>AsString</strong></font></td>
    <td width="10%">empty</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
    <td width="10%">*</td>
  </tr>
  <tr>
    <td width="10%" bgcolor="#800000"><font color="#FFFFFF"><strong>AsLongBinary</strong></font></td>
    <td width="10%">NULL</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">&nbsp;</td>
    <td width="10%">*</td>
  </tr>
  <tr>
    <td colspan="11">Empty cells indicate the conversion <strong>is not</strong> available,
    thus code asserts.<br>
    Cells marked with * indicate conversion <strong>is</strong> available (See the <a
    href="##conv_alg">Conversion algorithms</a> table for data conversion rules).</td>
  </tr>
</table>

<p>&nbsp;</p>

<table border="1" width="100%" cellspacing="0" cellpadding="2">
  <tr>
    <td width="100%" colspan="10" bgcolor="#C0C0C0"><p align="center"><a name="#conv_assign"></a><strong>Conversions
    made by assignment operators</strong></td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>Database Field Type</strong></font></td>
    <td width="89%" colspan="9" bgcolor="#008000"><p align="center"><font color="#FFFFFF"><strong>Argument
    of the assignment operator</strong></font></td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000">&nbsp;</td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>bool</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>unsigned
    char</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>short</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>int</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>long</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>float</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>double</strong></font></td>
    <td width="11%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>COleDateTime</strong></font></td>
    <td width="12%" align="center" bgcolor="#008000"><font color="#FFFFFF"><strong>String</strong></font></td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>NULL</strong></font></td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="12%">&nbsp;</td>
    <td width="12%">&nbsp;</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>BOOL</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">&nbsp;</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>UCHAR</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">&nbsp;</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>SHORT</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">&nbsp;</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>LONG</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">&nbsp;</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>SINGLE</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">&nbsp;</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>DOUBLE</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">&nbsp;</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>DATE</strong></font></td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="12%">*</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>STRING</strong></font></td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="11%">*</td>
    <td width="12%">*</td>
    <td width="11%">*</td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#800000"><font color="#FFFFFF"><strong>BINARY</strong></font></td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="11%">&nbsp;</td>
    <td width="12%">&nbsp;</td>
    <td width="12%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="10">Empty cells indicate the conversion <strong>is not</strong> available,
    thus code asserts.<br>
    Cells marked with * indicate conversion <strong>is</strong> available (See the <a
    href="##conv_alg">Conversion algorithms</a> table for data conversion rules).</td>
  </tr>
</table>

<p>&nbsp;</p>

<table border="1" width="100%" cellspacing="0" cellpadding="2">
  <tr>
    <td width="100%" colspan="2" align="center" bgcolor="#C0C0C0"><a name="#conv_alg"></a><strong>Conversion
    algorithms</strong></td>
  </tr>
  <tr>
    <td width="22%">String to Bool</td>
    <td width="78%">comparing the first character of the string with 'T'</td>
  </tr>
  <tr>
    <td width="22%">Char to Bool</td>
    <td width="78%">comparing the character with 'T'</td>
  </tr>
  <tr>
    <td width="22%">Bool to String</td>
    <td width="78%">String = (bVal) ? 'T' : 'F'</td>
  </tr>
  <tr>
    <td width="22%">Bool to Char</td>
    <td width="78%">Char = (bVal) ? 'T' : 'F'</td>
  </tr>
  <tr>
    <td width="22%">String to Number</td>
    <td width="78%">appropriate atoX() function</td>
  </tr>
  <tr>
    <td width="22%">Number to String</td>
    <td width="78%">CString::Format() method using the appropriate format specifier string</td>
  </tr>
  <tr>
    <td width="22%">String to Date</td>
    <td width="78%">COleDateTime::ParseDateTime() method</td>
  </tr>
  <tr>
    <td width="22%">Date to String</td>
    <td width="78%">COleDateTime::Format() method</td>
  </tr>
</table>

<p>&nbsp;</p>

<p><a name="#examples"></a><big><strong>Examples of how to use CODBCRecordset</strong></big></p>

<p>You should include the files <font color="#800000">ODBCRecordset.h</font> and <font
color="#800000">ODBCRecordset.cpp</font> in your project.</p>

<p>I usually include this line in my <font color="#800000">StdAfx.h</font> file.</p>

<pre><tt><font color="#990000">#include &quot;ODBCRecordset.h&quot;</font></tt></pre>

<p>Here is a simple code showing how CODBCRecordset can be used.</p>

<pre><tt><font color="#990000">/////////////////////////////////////////////////////////////////////////////
CDatabase	db;
//	This connect string will pop up the ODBC connect dialog
CString		cConnect = &quot;ODBC;&quot;;
db.Open( NULL,				//	DSN
	 FALSE,				//	Exclusive
	 FALSE,				//	ReadOnly
	 cConnect,			//	ODBC Connect string
	 TRUE				//	Use cursor lib
   );

COleDateTime	dOrderDate;

CODBCRecordset	rs( &amp;db );
<strong>rs.Open( &quot;SELECT * FROM Orders \
	WHERE ORDER_DATE &gt; 'jan 1 2000' \
	ORDER BY ORDER_DATE&quot; );
</strong>for( ; ! rs.IsEOF(); rs.MoveNext() )
{
//	The choice is yours. You may choose whatever way
//	you want to get the values
//
	//	These return COleDateTime value
	dOrderDate = <strong>rs.GetDate( &quot;ORDER_DATE&quot; );</strong>
	dOrderDate = <strong>rs.Field(&quot;ORDER_DATE&quot;).AsDate();</strong>

	//	These make implicit call to AsDate()
	dOrderDate = <strong>rs(&quot;ORDER_DATE&quot;);</strong>
	dOrderDate = <strong>rs.Field(&quot;ORDER_DATE&quot;);</strong>

	//	Now edit the fields in the recordset
	rs.Edit();
	<strong>rs(&quot;ORDER_DATE&quot;)</strong> = &quot;jan 1 1999&quot;;	// Implicit conversion
	<strong>rs.Field(&quot;ORDER_DATE&quot;)</strong> = &quot;jan 1 1999&quot;;  // Implicit conversion
	rs.Update();
}	//	for(....
/////////////////////////////////////////////////////////////////////////////
</font></tt></pre>

<p>If <strong>ORDER_DATE</strong> is stored in the database as <strong>datetime</strong>
or compatible data type the value will be get directly.<br>
If <strong>ORDER_DATE</strong> is stored in the database as <strong>string</strong> or
compatible data type (char, varchar) the value will be converted via
COleDateTime::ParseDateTime() method. If conversion fails, <strong>dOrderDate</strong>
will be set to <strong>COleDatetime::invalid</strong>.</p>

<p>When opening a resultset generated by join statements it is possible to get 2 or more
columns that have the same name. CODBCRecordset leaves the name of the first column intact
but other repeated columns are renamed with adding the number this columns repeats the
name. Not repeated column names are left intact. E.g.</p>

<p><tt><font color="#990000"><strong>SELECT * FROM Orders, Customers WHERE Orders.CUST_ID
= Customers.ID</strong></font></tt></p>

<p>If the table <em>Orders</em> have a column with name <em>ID</em> and <em>Customers</em>
have a column with name <em>ID</em>, CODBCRecordset will rename <em>ID</em> from Customers
to <strong>ID2</strong> and all other not repeating column names will be intact.</p>

<p>Well, here is a tip: Rename columns manualy to be sure what name they have, e.g.</p>

<p><tt><font color="#990000"><strong>SELECT Orders.*, Customers.ID as CUSTOMERS_ID <br>
&nbsp;&nbsp;&nbsp; FROM Orders, Customers <br>
&nbsp;&nbsp;&nbsp; WHERE Orders.CUST_ID = Customers.ID</strong></font></tt></p>

<p>&nbsp;</p>

<p><a name="#how_works"></a><big><strong>How does CODBCRecordset work?</strong></big></p>

<p>CODBCRecordset allocates storage for all fields in the resultset and uses MFC <em>Record
Field eXchange</em> mechanizm like it has been inherited from CRecordset using
ClassWizard.</p>

<p>That's all.</p>

<p><a href="ODBCRecordset.zip">Download source</a>&nbsp;&nbsp; ODBCRecordset.zip (13 KB)</p>

<hr>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -