问一个关于ADO连接的问题

[复制链接]
查看11 | 回复4 | 2010-5-13 09:34:23 | 显示全部楼层 |阅读模式
Dim myConnection As New SqlConnection()
Dim myDataAdapter As New SqlDataAdapter()
Dim myDataSet As New DataSet()
myConnection.ConnectionString = "initial catalog=pubs;integrated security=SSPI;persist security info=False;workstation id=IBM;packet size=4096"
myDataAdapter.SelectCommand = New SqlCommand()
myDataAdapter.SelectCommand.Connection = myConnection
myDataAdapter.SelectCommand.CommandText = "Select au_lname,au_fname,title,price From authors,titleauthor,titles" & _
" where authors.au_id=titleauthor.au_id and titleauthor.title_id=titles.title_id Order By au_lname,au_fname"
myDataAdapter.SelectCommand.CommandType = CommandType.Text
'myConnection.Open()
'myDataAdapter.SelectCommand.ExecuteNonQuery()
myDataAdapter.Fill(myDataSet, "aa&quot

'myConnection.Close()
grdAuthorTitles.DataSource = myDataSet
grdAuthorTitles.DataMember = "aa"
我已将打开/关闭连接注销,为何还能够得到数据填充表格?
回复

使用道具 举报

千问 | 2010-5-13 09:34:23 | 显示全部楼层
Here is what I got from MSDN -- Found it after a google search on "dataadapter fill dataset connection"...
The Fill method implicitly opens the Connection that the DataAdapter is using if it finds that the connection is not already open. If Fill opened the connection, it will also close the connection when Fill is finished.
回复

使用道具 举报

千问 | 2010-5-13 09:34:23 | 显示全部楼层
是不是忘记绑定了!
回复

使用道具 举报

千问 | 2010-5-13 09:34:23 | 显示全部楼层
最初由 eric.li.123 发布
[B]Here is what I got from MSDN -- Found it after a google search on "dataadapter fill dataset connection"...
The Fill method implicitly opens the Connection that the DataAdapter is using if it finds that the connection is not already open. If Fill opened the connection, it will also close the connection when Fill is finished. [/B]

Bingo
回复

使用道具 举报

千问 | 2010-5-13 09:34:23 | 显示全部楼层
.net的特点之一,把数据通过数据集放在内存中,不需每次连接数据源来读取数据,减少网络开销和数据库的连接负担。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行