& “Initial Catalog = 商品经营管理数据库;Data Source=(local)”
3 i, N+ [) P0 G( V* \! SmyCnn.Open ‘别忘了“打开”5 y9 N* e$ c+ d1 C' t$ e
myRs.Source = “select * from T_Customer”1 q7 y5 u: W" c: i
myRs.ActiveConnection = myCnn
: y8 t t' X& P8 U* O, T+ `: C4 _myRs.CursorType = adOpenDynamic
E6 q5 {; n+ W% A* v0 omyRs.CursorLocation = adUseClient% m% P! {" A" h5 Q x% j& F9 K
myRs.Open , , , , adCmdTalbe: b; j& {2 |1 ~, A
17.18 创建RecordSet对象的三种方法:
9 k/ r7 c# G/ I' @( W6 [1)使用Connection对象:Set myRs = myConn.Execute(“select * from T_customer”); ^+ N+ L7 N) k6 M2 t3 B' a) V
2)使用Command对象:Set myRs = myComm.Execute;
; K& |7 D% P0 c W4 u" ?- A3)直接使用Open方法:myRs.Open , , , ,8 O+ Y" h* z9 h( f6 N% _0 h
17.19 Error对象:如果最后一次的操作成功则这个集合为空。只有在OLE DB层产生错误才会将每个错误被翻译成Error对象,如果指向一个不存在的提供者则Errors集合不会得到任何信息,因为ADO不能发现这个指定的驱动程序,因此会将错误传递到Visual Basic Errors中。
% j; Y7 v) \8 S4 k17.20 三对象结合使用的典型示例:. K7 c& Z# ]5 C0 x; V
Dim myCnn As New ADODB.Connection: C2 {3 P% O4 p. R* Y
Dim myCmm As New ADODB.Command
0 \, y+ T; T4 U1 M# _5 RDim myRs As New ADODB.RecordSet
0 J" ]. R# g* ?. q. o3 `9 f$ t9 QmyCnn.ConnectionString = “Provider = SQLOLEDB.1;User ID = loginID;” _7 P- {2 I H4 Z z9 u) l s/ N
& “Initial Catalog = jessymin;Data Source =(local) ”& ~9 y: a5 l5 R* Q% V1 R3 T
myCnn.Open ‘别忘了“打开”8 m( H5 f+ } u- y/ [3 t1 Y
Set myCmm.ActiveConnection = myCnn
1 k8 E6 I/ O- c- ~myCmm.CommandText = “select * from T_Customer”
- y, j7 x* F* S) O! k. SSet myRs = myCmm.Execute; ~; }& l; p# c# t# \
17.21 VB自定义函数示例:将字段空值转化为空字符串
$ U& R e3 _% N) d6 b: k S: oPrivate Function convertNull(val As Variant) As Variant
9 T6 w0 A: r- v8 G+ w. @6 DIf IsNull(val) = True Then
3 s2 X5 j* r. b; H6 [4 \convertNull = “”
7 E, z- C- F7 Q0 C* C SElse7 @! f( N- }/ _/ {) x& f
convertNull = val" C6 G& j0 s/ |1 t
End If
, }) M1 X" g, Y* W2 [ c# ZEnd Function |