青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆-9  評論-6  文章-0  trackbacks-0

Microsoft Corporation

April 2, 1998
Updated March 30, 2004

Applies to:
??? Microsoft? ActiveX? Data Objects (ADO)

Summary: This is the first in a series of columns that will explore the individual objects in Microsoft ActiveX Data Objects (ADO).

Contents
What Is a Connection Object?
What Are the Connection Object's Methods and Properties?
How Do I Use the Connection Object to Connect to a Data Store?
How Do I Use the Connection Object to Execute a Command?

What Is a Connection Object?
A Connection object represents a physical connection to a data store. To create a Connection object, you will supply the name of either an ODBC data store or an OLE DB provider. When you open the Connection object, you attempt to connect to the data store. The State property of the Connection object tells you whether you succeeded or failed. You can send SQL statements or run stored procedures by using the Execute method of the Connection object. If the command you send to the data store returns records, a Recordset object will be created automatically. You close the Connection object when you are through with it.

What Are the Connection Object's Methods and Properties?
The following table lists some of the more commonly used methods of the Connection object.

The following table lists some of the more commonly used methods of the Connection object.

Method Description
Open Opens a connection to a data store.
Close Closes a connection and any dependent objects.
Execute Executes the specified query, SQL statement, stored procedure, or provider-specific text.
BeginTrans Begins a new transaction.
CommitTrans Saves any changes and ends the current transaction. It may also start a new transaction.
RollbackTrans Cancels any changes made during the current transaction and ends the transaction. It may also start a new transaction.

The following table lists some of the more commonly used properties of the Connection object.

Property Description
ConnectionString Contains the information used to establish a connection to a data store.
ConnectionTimeout Indicates how long to wait while establishing a connection before terminating the attempt and generating an error.
CommandTimeout Indicates how long to wait while executing a command before terminating the attempt and generating an error.
State Indicates whether a connection is currently open, closed, or connecting.
Provider Indicates the name of the provider used by the connection.
Version Indicates the ADO version number.
CursorLocation Sets or returns a value determining who provides cursor functionality.

How Do I Use the Connection Object to Connect to a Data Store?
To use a Connection object, simply specify a connection string, which identifies the data store you want to work with, and then call the Open method to connect.

The easiest way to open a connection is to pass the connection string information to the Open method. To determine whether the Connection object worked, you can use the State property of the Connection object. State returns adStateOpen if the Connection object is open and adStateClosed if it isn't. Here is an example of connecting to SQL Server by using an ODBC data store:

Sub ?ConnectionExample1()
???
Dim ?cnn? As ?ADODB.Connection
???
Set ?cnn? = ? New ?ADODB.Connection

???
' ?Open?a?Connection?using?an?ODBC?DSN?named?"Pubs".
???cnn.Open? " Pubs " ,? " MyUserName " ,? " MyPassword "

???
' ?Find?out?if?the?attempt?to?connect?worked.
??? If ?cnn.State? = ?adStateOpen? Then
??????
MsgBox ? " Welcome?to?Pubs! "
???
Else
??????
MsgBox ? " Sorry.?No?Pubs?today. "
???
End ? If

???
' ?Close?the?connection.
???cnn.Close

End?Sub

If you need to connect to only one data store, the procedure followed in the above code is the easiest way. Alternatively, you can create a Connection object and set the ConnectionString property before calling the Open method. This approach allows you to connect to one data store and then reuse the Connection object to connect to another data store.

This method also gives you the opportunity to set other properties of the Connection object before connecting. For instance, you might want to set the connection time-out:

Sub ?ConnectionExample2()
???
Dim ?cnn? As ?ADODB.Connection
???
Set ?cnn? = ? New ?ADODB.Connection?

???
' ?Open?a?connection?using?an?ODBC?DSN?"Pubs".
???cnn.ConnectionString? = ? " DSN=Pubs;UID=MyUserName;PWD=MyPassword; "
???cnn.Open?

???
' ?Find?out?if?the?attempt?to?connect?worked.
??? If ?cnn.State? = ?adStateOpen? Then
??????
MsgBox ? " Welcome?to?Pubs! "
???
Else
??????
MsgBox ? " Sorry.?No?Pubs?today. "
???
End ? If ?

???
' ?Close?the?connection.
???cnn.Close?

End?Sub
?


?

Sub ?ConnectionExample3()
???
Dim ?cnn? As ?ADODB.Connection
???
Set ?cnn? = ? New ?ADODB.Connection?

???
' ?Set?properties?of?the?Connection.
???cnn.ConnectionString? = ? " DSN=Pubs;UID=MyUserName;PWD=MyPassword; "
???cnn.ConnectionTimeout?
= ? 30 ?

???
' ?Open?the?connection.
???cnn.Open?

???
' ?Find?out?if?the?attempt?to?connect?worked.
??? If ?cnn.State? = ?adStateOpen? Then
??????
MsgBox ? " Welcome?to?Pubs! "
???
Else
??????
MsgBox ? " Sorry.?No?Pubs?today. "
???
End ? If ?

???
' ?Close?the?connection.
???cnn.Close?

End?Sub
?

?

This syntax for the ConnectionString property assumes that the data store has already been created by using the ODBC Administrator (or in code). It is becoming increasingly popular to not have to rely on existing ODBC data stores. This eases the setup burden. The next example shows an alternative method for connecting to SQL Server, relying merely on the existence of the ODBC driver itself:

?

Sub ?ConnectionExample4()
???
Dim ?cnn? As ?ADODB.Connection
???
Set ?cnn? = ? New ?ADODB.Connection?

???
' ?Open?a?connection?by?referencing?the?ODBC?driver.
???cnn.ConnectionString? = ? " driver={SQL?Server}; " ? & ?_
??????
" server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs "
???cnn.Open?

???
' ?Find?out?if?the?attempt?to?connect?worked.
??? If ?cnn.State? = ?adStateOpen? Then
??????
MsgBox ? " Welcome?to?Pubs! "
???
Else
??????
MsgBox ? " Sorry.?No?Pubs?today. "
???
End ? If ?

???
' ?Close?the?connection.
???cnn.Close?

End?Sub
?

Today there are a wide variety of ODBC drivers you can use with ADO to talk to data. In the future, there will be more OLE DB providers available to connect to data stores. The Microsoft? OLE DB Provider for ODBC is currently the default provider for ADO. You can use a different provider by setting the Provider property of the Connection object.

?

Sub ?ConnectionExample5()
???
Dim ?cnn? As ?ADODB.Connection
???
Set ?cnn? = ? New ?ADODB.Connection?

???
' Set?the?provider?property?to?the?OLE?DB?Provider?for?ODBC.
???cnn.Provider? = ? " MSDASQL " ?

???
' ?Open?a?connection?using?an?ODBC?DSN.
???cnn.ConnectionString? = ? " driver={SQL?Server}; " ? & ?_
??????
" server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs "
???cnn.Open?

???
' ?Find?out?if?the?attempt?to?connect?worked.
??? If ?cnn.State? = ?adStateOpen? Then
??????
MsgBox ? " Welcome?to?Pubs! "
???
Else
??????
MsgBox ? " Sorry.?No?Pubs?today. "
???
End ? If ?

???
' ?Close?the?connection.
???cnn.Close?

End?Sub


?

Sub ?ConnectionExample5()
???
Dim ?cnn? As ?ADODB.Connection
???
Set ?cnn? = ? New ?ADODB.Connection?

???
' Set?the?provider?property?to?the?OLE?DB?Provider?for?ODBC.
???cnn.Provider? = ? " MSDASQL " ?

???
' ?Open?a?connection?using?an?ODBC?DSN.
???cnn.ConnectionString? = ? " driver={SQL?Server}; " ? & ?_
??????
" server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs "
???cnn.Open?

???
' ?Find?out?if?the?attempt?to?connect?worked.
??? If ?cnn.State? = ?adStateOpen? Then
??????
MsgBox ? " Welcome?to?Pubs! "
???
Else
??????
MsgBox ? " Sorry.?No?Pubs?today. "
???
End ? If ?

???
' ?Close?the?connection.
???cnn.Close?

End?Sub
?


In the code above, setting the Provider property is not necessary because the OLE DB Provider for ODBC is the default provider for ADO. However, this shows you how you would change the provider when you want to use other OLE DB providers.

How Do I Use the Connection Object to Execute a Command?
The Execute method is used to send a command (an SQL statement or some other text) to the data store. If the SQL statement returns rows, a Recordset object is created. (The Execute method always returns a Recordset object, but it is a closed Recordset if the command doesn't return results.)

Sub ?ConnectionExample6()
???
Dim ?cnn? As ?ADODB.Connection
???
Dim ?rs? As ?ADODB.Recordset?

???
Set ?cnn? = ? New ?ADODB.Connection?

???
' ?Open?a?connection?by?referencing?the?ODBC?driver.
???cnn.ConnectionString? = ? " driver={SQL?Server}; " ? & ?_
??????
" server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs "
???cnn.Open?

???
' ?Create?a?Recordset?by?executing?an?SQL?statement.
??? Set ?rs? = ?cnn.Execute( " Select?*?From?authors " )?

???
' ?Show?the?first?author.
??? MsgBox ?rs( " au_fname " )? & ? " ? " ? & ?rs( " au_lname " )?

???
' ?Close?the?connection.
???rs.Close?

End?Sub
?

Remember that the returned Recordset object from connection.execute is always a read-only, forward-only cursor. If you need a Recordset object with more functionality, you should first create a Recordset object with the desired property settings and then use the Recordset object's Open method to execute the query and return the desired cursor type.

In the following example, the command passed to the data source is a Delete statement. Because no rows are returned, you do not need to explicitly use a Recordset object. How many rows were deleted? You can use the recordsAffected parameter to find out.

?

Sub ?ConnectionExample7()
???
Dim ?cnn? As ?ADODB.Connection
???
Dim ?rs? As ?ADODB.Recordset?

???
Set ?cnn? = ? New ?ADODB.Connection?

???
' ?Open?a?connection?by?referencing?the?ODBC?driver.
???cnn.ConnectionString? = ? " driver={SQL?Server}; " ? & ?_
??????
" server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs "
???cnn.Open?

???
' ?Send?a?Delete?statement?to?the?database.
???cnn.Execute?( " Delete?From?authors?Where?au_id?=?'011-01-0111' " )?

???
' ?Find?out?how?many?rows?were?affected?by?the?Delete.
??? Set ?rs? = ?cnn.Execute( " Select?@@rowcount " )
???
' ?Display?the?first?field?in?the?recordset.
??? MsgBox ?rs( 0 )? & ? " ?rows?deleted " ?

???
' ?Close?the?connection.
???rs.Close?

End?Sub
?

In the next example, the command passed to the data store specifies the name of a stored procedure to run. Because rows are returned, you do need to use a Recordset object.

?

Sub ?ConnectionExample8()
???
Dim ?cnn? As ?ADODB.Connection
???
Dim ?rs? As ?ADODB.Recordset?

???
Set ?cnn? = ? New ?ADODB.Connection?

???
' ?Open?a?connection?by?referencing?the?ODBC?driver.
???cnn.ConnectionString? = ? " driver={SQL?Server}; " ? & ?_
??????
" server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs "
???cnn.Open?

???
' ?Create?a?recordset?by?running?a?stored?procedure.
??? Set ?rs? = ?cnn.Execute( " Exec?byroyalty?50 " )?

???
' ?Loop?through?the?recordset?and?show?the?author's?ID.
??? Do ? While ? Not ?rs.EOF
??????
MsgBox ?rs( " au_id " )
??????rs.MoveNext
???
Loop ?

???
' ?Close?the?connection.
???rs.Close?

End?Sub
?

posted on 2006-06-06 09:41 小石頭 閱讀(395) 評論(0)  編輯 收藏 引用
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲精品欧洲精品| 你懂的国产精品| 亚洲最新视频在线播放| 麻豆成人在线播放| 欧美不卡一区| 欧美在线日韩| 免费毛片一区二区三区久久久| 国产日韩成人精品| 欧美在线免费观看| 亚洲精品国产精品国产自| 日韩午夜在线视频| 欧美激情在线| 久久精品国产成人| 亚洲激情一区二区三区| 亚洲一区二区精品| 在线观看亚洲专区| 国产精品中文在线| 男女av一区三区二区色多| 一本色道久久88综合亚洲精品ⅰ| 性欧美精品高清| 亚洲精品综合精品自拍| 欧美aa国产视频| 亚洲欧美在线播放| 亚洲精品欧美精品| 激情久久影院| 国产日韩欧美麻豆| 欧美午夜视频| 欧美精品日韩一区| 蜜臀a∨国产成人精品| 亚洲欧美中文另类| 亚洲在线视频| 亚洲欧美日本视频在线观看| 亚洲精品精选| 亚洲国产福利在线| 亚洲高清自拍| 蜜桃久久av一区| 欧美激情免费观看| 亚洲第一在线综合网站| 亚洲国产精品精华液2区45| 欧美电影专区| 亚洲国产精品一区制服丝袜| 欧美黄色片免费观看| 欧美高清影院| 亚洲激情婷婷| 欧美在线不卡| 久久国产视频网站| 老鸭窝亚洲一区二区三区| 免费在线日韩av| 91久久中文| 亚洲欧美视频一区二区三区| 新狼窝色av性久久久久久| 久久久久久久久久看片| 免费影视亚洲| 国产日韩欧美麻豆| 亚洲黄色性网站| 翔田千里一区二区| 亚洲第一色中文字幕| 中日韩美女免费视频网站在线观看| 亚洲欧美国产制服动漫| 久久久久国产精品一区三寸 | 欧美成人综合| 亚洲区在线播放| 午夜在线电影亚洲一区| 免费h精品视频在线播放| 欧美日韩国产综合视频在线| 国产真实久久| 欧美一二区视频| 亚洲精品国产精品久久清纯直播| 亚洲性感激情| 欧美日韩91| 日韩视频一区二区三区| 久久久久久久综合色一本| 亚洲最快最全在线视频| 欧美成人精品一区二区| 136国产福利精品导航网址应用| 亚洲宅男天堂在线观看无病毒| 欧美激情第三页| 狂野欧美激情性xxxx欧美| 国产亚洲精品久久久久婷婷瑜伽 | 日韩一级精品视频在线观看| 可以免费看不卡的av网站| 午夜精品三级视频福利| 国产精品一区二区男女羞羞无遮挡| avtt综合网| 99re热这里只有精品视频| 欧美国产精品久久| 欧美高清视频一区二区| 亚洲最新视频在线| 日韩一级片网址| 国产精品国产精品| 久久成人在线| 麻豆91精品91久久久的内涵| 在线观看一区| 亚洲免费观看视频| 国产欧美日韩伦理| 欧美高清hd18日本| 欧美精品成人一区二区在线观看 | 亚洲乱码国产乱码精品精98午夜| 亚洲激情午夜| 国产综合色产| 99热这里只有成人精品国产| 国产精品无码专区在线观看| 欧美成人免费在线| 国产视频欧美| 一本在线高清不卡dvd | 欧美国产视频在线观看| 欧美日韩国产精品| 久久只精品国产| 国产精品国产精品| 欧美韩日亚洲| 国产一区二区欧美| 亚洲无吗在线| 一区二区三区四区精品| 蜜桃av久久久亚洲精品| 久久福利精品| 国产精品推荐精品| 亚洲欧洲日产国码二区| 亚洲成人在线观看视频| 久久国产一区二区| 久久久久国产精品一区三寸 | 夜夜嗨av一区二区三区网站四季av | 亚洲三级电影在线观看| 久久久噜噜噜久噜久久| 欧美午夜在线| 亚洲宅男天堂在线观看无病毒| 亚洲精品乱码久久久久久日本蜜臀| 亚洲在线国产日韩欧美| 欧美一区二区三区精品| 国产精品高潮呻吟视频| 一区二区三区 在线观看视频 | 亚洲人被黑人高潮完整版| 久久久久国产精品一区二区| 久久综合激情| 精品白丝av| 欧美韩国在线| 在线一区二区三区做爰视频网站| 亚洲综合久久久久| 国产日本欧美一区二区| 久久国产精品第一页| 亚洲第一搞黄网站| 亚洲男人的天堂在线aⅴ视频| 国产精品一区二区欧美| 久久久噜噜噜久噜久久 | 亚洲无线观看| 久久久久久久久久久久久女国产乱 | 亚洲欧美bt| 亚洲国产高清aⅴ视频| 欧美色视频日本高清在线观看| 亚洲视频一区二区在线观看 | 一本色道久久88综合亚洲精品ⅰ| 亚洲欧美综合v| 亚洲福利视频二区| 国产美女在线精品免费观看| 免费欧美高清视频| 欧美影视一区| 夜夜嗨av一区二区三区四季av | 午夜精品久久久久久久男人的天堂 | 一本色道婷婷久久欧美| 欧美激情精品久久久久久久变态| 欧美精品久久久久a| 香蕉精品999视频一区二区| 亚洲一区观看| aa日韩免费精品视频一| 亚洲欧美国产制服动漫| 香蕉亚洲视频| 亚洲激情第一页| 亚洲性夜色噜噜噜7777| 久久久久免费观看| 欧美三级特黄| 亚洲二区在线| 性娇小13――14欧美| 在线综合亚洲| 亚洲网站在线播放| 亚洲女同性videos| 久久久久久免费| 日韩网站在线观看| 亚洲在线观看视频网站| 欧美在线国产精品| 欧美激情视频网站| 国产精品视频成人| 在线观看欧美亚洲| 亚洲午夜极品| 麻豆精品在线播放| 一本久道久久综合中文字幕| 香蕉乱码成人久久天堂爱免费| 免费成人av资源网| 国产美女高潮久久白浆| 亚洲国产女人aaa毛片在线| 午夜日韩在线观看| 亚洲国产精品999| 午夜精品在线视频| 欧美日韩在线另类| 在线观看国产精品淫| 午夜精品福利在线| 91久久国产综合久久| 久久久久久久久久久久久女国产乱 | 国产精品区一区二区三区| 亚洲欧洲美洲综合色网| 蜜臀av一级做a爰片久久| 一区二区激情视频|