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

隨筆-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>
            欧美在线视频导航| 欧美在线你懂的| 亚洲精品乱码| 国产精品久久久亚洲一区| 亚洲午夜羞羞片| 欧美专区在线播放| 精品999网站| 美女视频黄 久久| 欧美一区二区成人| 激情视频亚洲| 久久精品动漫| 久久精品国产亚洲精品| 欧美二区在线观看| 亚洲欧美日韩精品一区二区| 久久午夜电影网| 亚洲最新合集| 欧美专区在线播放| 老司机67194精品线观看| 狠狠色丁香婷婷综合影院| 免费成人毛片| 99pao成人国产永久免费视频| 免费成人高清在线视频| 蜜臀久久久99精品久久久久久| 狠久久av成人天堂| 夜夜精品视频| 亚洲国产另类精品专区| 亚洲综合首页| 黄页网站一区| 亚洲一级黄色片| 亚洲娇小video精品| 亚洲高清资源综合久久精品| 国产午夜亚洲精品不卡| 久久国产精品第一页| 久久综合久久88| 亚洲欧洲精品成人久久奇米网| 欧美日韩国产精品自在自线| 一本色道久久加勒比精品 | 国产日韩欧美在线观看| 亚洲视频专区在线| 久久久午夜电影| 亚洲高清一区二| 欧美精品久久久久久久| 亚洲精品小视频在线观看| 一本色道久久综合亚洲精品婷婷| 午夜欧美不卡精品aaaaa| 午夜在线不卡| 欧美色精品天天在线观看视频| 一本色道精品久久一区二区三区| 亚洲毛片一区二区| 欧美三级不卡| 久久一区欧美| 亚洲欧美日韩在线播放| 裸体丰满少妇做受久久99精品| 欧美久久久久久| 一区二区不卡在线视频 午夜欧美不卡'| 一本久久知道综合久久| 激情懂色av一区av二区av| 欧美极品一区二区三区| 欧美在线观看视频一区二区三区 | 久久精品夜色噜噜亚洲a∨ | 久久久五月婷婷| 99视频精品| 怡红院av一区二区三区| 欧美日韩一区视频| 免费亚洲一区| 美女精品视频一区| 欧美在线欧美在线| 午夜精品久久久久影视| 日韩香蕉视频| 免费黄网站欧美| 欧美一区二区三区视频在线| 麻豆精品一区二区av白丝在线| 欧美日韩视频第一区| 欧美粗暴jizz性欧美20| 欧美视频官网| 国产精品三上| 欧美性感一类影片在线播放 | 亚洲欧美卡通另类91av | 国内精品久久久久久影视8| 国产精品日韩在线| 99精品视频一区| 在线视频成人| 午夜日韩在线| 久久久福利视频| 亚洲福利国产精品| 亚洲娇小video精品| 蜜臀久久99精品久久久久久9| 日韩视频免费在线| 欧美日韩精品一区二区| 久久婷婷国产综合精品青草| 国产精品久久久久久一区二区三区| 久久久精品一品道一区| 国产精品一区二区女厕厕| 一本久道久久综合婷婷鲸鱼| 伊人蜜桃色噜噜激情综合| 欧美怡红院视频一区二区三区| 午夜亚洲性色视频| 国产精品亚洲аv天堂网| 一区二区激情小说| 亚洲伊人观看| 老司机精品视频网站| 一区二区三区成人| 亚洲欧美精品在线观看| 性娇小13――14欧美| 久久一区国产| 久久全球大尺度高清视频| 欧美成人精品在线视频| 欧美亚洲一区| 欧美日韩久久不卡| 亚洲视频在线看| 久热精品在线| 亚洲国产美女精品久久久久∴| 久久精品一区二区三区不卡牛牛 | 亚洲综合欧美日韩| 美日韩精品免费观看视频| 亚洲人成亚洲人成在线观看| 国内伊人久久久久久网站视频 | 亚洲综合色丁香婷婷六月图片| 亚洲永久免费| 午夜精品久久久久久久99黑人| 久久国产一区二区三区| 国内精品视频在线播放| 久久五月婷婷丁香社区| 欧美在线一区二区| 国产精品综合久久久| 性视频1819p久久| 久热re这里精品视频在线6| 亚洲电影免费观看高清完整版在线观看 | 国产精品久久影院| 亚洲在线成人| 久久人人97超碰国产公开结果| 日韩亚洲欧美综合| 久久久久一区二区| 在线亚洲欧美视频| 欧美日韩aaaaa| 亚洲在线不卡| 久久精品日韩欧美| 欧美成人午夜影院| 亚洲一区二区在| 亚洲高清激情| 国产精品实拍| 欧美精品日韩一区| 久久黄色小说| 亚洲一区二区av电影| 欧美激情区在线播放| 性欧美精品高清| 亚洲美女淫视频| 亚洲国产国产亚洲一二三| 亚洲另类春色国产| 国产亚洲欧美另类一区二区三区| 欧美大色视频| 久久久久一区二区| 亚洲自拍三区| 艳妇臀荡乳欲伦亚洲一区| 女女同性精品视频| 久久激情婷婷| 亚洲国产欧美一区二区三区同亚洲 | 美女国产一区| 亚洲欧美一区二区激情| 亚洲精品一区二区三区四区高清 | 亚洲视频播放| 亚洲激情偷拍| 在线播放视频一区| 国产综合精品| 国产午夜亚洲精品不卡| 国产精品视频午夜| 国产精品wwwwww| 欧美日韩在线播放三区| 欧美激情综合五月色丁香| 美女任你摸久久| 免费观看30秒视频久久| 久久亚洲精品网站| 久久影视精品| 美女精品网站| 欧美激情国产日韩| 欧美国产亚洲另类动漫| 蜜臀久久久99精品久久久久久| 久久中文字幕一区| 久久综合狠狠综合久久综合88| 久久蜜桃香蕉精品一区二区三区| 久久精品亚洲| 久久久蜜臀国产一区二区| 久久嫩草精品久久久精品| 久久综合电影| 欧美精品日韩综合在线| 欧美日韩亚洲视频一区| 国产精品国产精品国产专区不蜜| 国产精品久久久久久久久动漫 | 亚洲一区网站| 欧美一区二区三区免费看| 久久精品五月| 免费一区二区三区| 亚洲国产美女| 99国产欧美久久久精品| 亚洲一区中文| 欧美在线日韩精品| 欧美1级日本1级| 欧美午夜精品| 国产日韩在线不卡| 亚洲国产二区|