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

隨筆-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>
            日韩一级精品视频在线观看| 99re6这里只有精品视频在线观看| 在线观看日韩av电影| 亚洲第一精品福利| 男女激情久久| 久久久久久久999精品视频| 欧美电影在线| 另类天堂av| 伊人男人综合视频网| 国产日韩亚洲| 亚洲视频播放| 亚洲一区一卡| 欧美高清视频www夜色资源网| 久久本道综合色狠狠五月| 欧美精品aa| 中日韩高清电影网| 日韩香蕉视频| 欧美小视频在线观看| 一本色道久久综合狠狠躁篇怎么玩| 国产日韩一区二区三区| 久久精品夜色噜噜亚洲aⅴ| 久久精品卡一| 亚洲激情网站| 国产精品成人一区二区三区夜夜夜| 亚洲精品国产欧美| 久久国产精品72免费观看| 伊人久久大香线| 欧美高清不卡| 亚洲欧美激情四射在线日| 久久久久久欧美| 亚洲国内精品| 国产综合久久| 欧美日韩综合视频| 久久久久这里只有精品| 亚洲三级影片| 欧美电影在线观看完整版| 9色精品在线| 亚洲国产日韩一区二区| 国产精品婷婷| 欧美精品在线看| 噜噜噜久久亚洲精品国产品小说| 欧美福利视频网站| 亚洲一区二区三区高清| 欧美国产日韩一区二区| 欧美一区二区三区日韩视频| 亚洲人成在线观看一区二区 | 国产精品免费视频xxxx| 欧美暴力喷水在线| 久久久久久香蕉网| 久久精品国产亚洲一区二区三区| 日韩一本二本av| 99精品国产高清一区二区| 男男成人高潮片免费网站| 久久精品综合一区| 欧美成在线观看| 亚洲大片精品永久免费| 亚洲黄色在线| 一区二区三区 在线观看视频| 亚洲理论在线| 午夜精品影院| 欧美大片va欧美在线播放| 欧美成人午夜激情| 国产精品午夜国产小视频| 永久域名在线精品| 亚洲国产日本| 亚洲欧美日本伦理| 亚洲承认在线| 欧美一级片久久久久久久| 久久黄色网页| 国产精品福利在线| 亚洲国产精品久久久久秋霞蜜臀| 夜夜嗨av一区二区三区四区 | 国产精品一二三视频| 国产欧美亚洲视频| 亚洲欧洲精品一区| 亚洲欧美激情诱惑| 亚洲欧洲在线播放| 午夜精品美女自拍福到在线| 噜噜噜在线观看免费视频日韩| 欧美日韩国产精品 | 亚洲午夜久久久| 老司机免费视频一区二区三区| 国产精品一区视频网站| 亚洲区一区二| 欧美成人一区二区三区片免费 | 日韩午夜在线观看视频| 另类图片国产| 免费观看成人鲁鲁鲁鲁鲁视频| 国产精品a久久久久久| 亚洲毛片在线看| 亚洲清纯自拍| 欧美va亚洲va国产综合| 亚洲激情av| 欧美激情2020午夜免费观看| 久久综合色影院| 91久久久久久久久久久久久| 欧美 亚欧 日韩视频在线| 欧美中文字幕第一页| 国产视频一区在线观看| 欧美与欧洲交xxxx免费观看| 午夜精品久久久久久| 国产一区二区高清不卡| 久久在线免费视频| 国产日韩欧美在线看| 久久精品99国产精品酒店日本| 欧美伊人久久久久久久久影院| 国产一区二区视频在线观看| 理论片一区二区在线| 久久精品视频va| 国产精品99久久99久久久二8| 一本一道久久综合狠狠老精东影业| 欧美三级午夜理伦三级中视频| 亚洲欧美精品在线观看| 久久精品视频在线看| 亚洲久久在线| 美女主播精品视频一二三四| 亚洲一区二区三| 欧美电影打屁股sp| 久久精品国产精品亚洲精品| 欧美色大人视频| 亚洲日本中文字幕免费在线不卡| 国产综合网站| 欧美怡红院视频一区二区三区| 这里只有精品视频在线| 久久综合精品一区| 欧美电影免费观看高清| 在线观看视频欧美| 老司机aⅴ在线精品导航| 久久久久国产一区二区| 国产日韩欧美综合| 久久精品一区四区| 久久精品人人做人人爽电影蜜月| 欧美深夜影院| 欧美亚洲一区二区三区| 久久精品色图| 亚洲第一精品影视| 欧美精品一区二区三区很污很色的| 久久夜色精品国产| 亚洲电影免费观看高清完整版在线观看| 亚洲欧美日韩精品久久久| 欧美日韩亚洲在线| 亚洲欧美日韩区| 免费欧美在线| 一区二区三区欧美激情| 国产色综合久久| 欧美精品观看| 欧美一区二区三区另类| 欧美大片在线影院| 亚洲欧美国产精品专区久久| 国内精品视频在线观看| 欧美日韩精品一二三区| 欧美在线播放视频| 亚洲精品专区| 欧美国产亚洲视频| 久久久久久亚洲精品杨幂换脸| 在线欧美日韩| 狠狠色狠狠色综合日日tαg| 欧美日韩亚洲综合| 蜜月aⅴ免费一区二区三区 | 国产永久精品大片wwwapp| 欧美日韩123| 欧美aⅴ99久久黑人专区| 午夜国产不卡在线观看视频| 亚洲人成网站999久久久综合| 久久久精品动漫| 久久九九免费视频| 久久精品30| 久久九九免费视频| 欧美在线免费观看| 欧美在线免费| 乱人伦精品视频在线观看| 欧美一区二区三区免费在线看| 亚洲一区二区三区影院| 亚洲一区二区三区四区视频| 亚洲一区久久| 亚洲欧美一区二区三区极速播放 | 99视频精品在线| 一本一本久久a久久精品牛牛影视| 亚洲精品日韩激情在线电影| 日韩视频中午一区| 亚洲制服av| 久久尤物视频| 国产精品福利在线观看| 国产精品中文字幕欧美| 国产在线观看91精品一区| 亚洲承认在线| 欧美亚洲免费电影| 亚洲黄色毛片| 香蕉久久夜色| 欧美日韩国产在线播放网站| 欧美午夜宅男影院| 最新亚洲视频| 久久婷婷综合激情| 亚洲一区二区三区在线| 蜜桃av噜噜一区| 国产午夜精品久久久久久久| 亚洲精品日产精品乱码不卡| 久久视频免费观看| 欧美在线看片| 国产在线视频欧美|