主题:  Coldfusion与ADO的连接的例子

5DDC版主

职务:版主
等级:6
金币:10.0
发贴:3820
注册:2002/3/25 21:30:11
#12002/4/30 9:25:54
用asp的人可以通过下面的例子将你的代码很快转到CF.


/* Set variables for establishing the ODBC connection (change to
your values) */
Datasource = "Comet"; // Datasource name
UserName = ""; // Username (if applicable)
Password = ""; // Password (if applicable)

/* The SQL we want to run */
SQL = "SELECT * FROM Topics ORDER BY TopicName ASC";

/* Create the ADO Connection object and open a new connection to
the datasource */
MyConnection = CreateObject("COM", "ADODB.Connection");
MyConnection.Open
("DSN=#Datasource#", "#UserName#", "#Password#", -1);

/* Execute the SQL against the ADO connection */
MyRecordset = MyConnection.Execute(SQL, 0, 8);

/* Return a collection of the fields returned by the SQL */
MyFields = MyRecordset.Fields;

/* We need to manually see how many records exist */
/* The RecordCount property of 'MyRecordset' won't do, since it
returns -1 */
RecordCount = 0;
while(NOT MyRecordset.EOF){
RecordCount = RecordCount + 1; // Increment the count
MyRecordset.MoveNext(); // Proceed to the next record
}

/* Initialize a variable to hold our column list */
Columns = "";



No records exist.









































#this#
#Evaluate(this)#







woogia

职务:普通成员
等级:1
金币:0.0
发贴:202
注册:2005/6/24 13:05:56
#22005/10/28 0:12:18
CF 中可以 CreateObject 啊.