重用DataReader [英] Reusing DataReader

查看:73
本文介绍了重用DataReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个完全相同的下拉菜单,我不想重新阅读
每个



有没有办法做下面我读取数据的内容,绑定到

depCity1然后绑定到destCity2。我发现第二个总是

是空白的。我认为这是因为DataReader只是预读。


************************* ************************* ******

connect.open()

cmdSelect =新OleDbCommand(" exec populateCities''北美'',连接)

dtReader = cmdSelect.ExecuteReader()


depCity1 .Datasource = dtReader

depCity1.DatatextField =" city_name"

depCity1.DataBind()


destCity2.Datasource = dtReader

destCity2.DatatextField =" city_name"

destCity2.DataBind()

connect.close()

********************************************
/>
如果我不能重复使用我已经拥有的dtReader,我该如何快速制作

dest2City2 = depCity1?


此外,我有一个没有传回标题的存储过程。

有一种方法可以执行上述操作,例如:


depCity1.DataTextField = dtReader(0)。

我知道上面的说法不正确,只是想找个方法来看看

第0栏。


谢谢,


汤姆。

I have 2 dropdowns that are exactly the same and I don''t want to re-read
for each.

Is there a way to do something like below where I read the data, bind to
depCity1 and then bind to destCity2. I find that the second one always
is blank. I assume this is because the DataReader is read-forward only.

************************************************** ******
connect.open()
cmdSelect = New OleDbCommand("exec populateCities ''North America''",connect)
dtReader = cmdSelect.ExecuteReader()

depCity1.Datasource = dtReader
depCity1.DatatextField = "city_name"
depCity1.DataBind()

destCity2.Datasource = dtReader
destCity2.DatatextField = "city_name"
destCity2.DataBind()
connect.close()
********************************************

If I can''t reuse the dtReader I already have, how do I quickly make
dest2City2 = depCity1?

Also, I have a stored procedure that doesn''t pass back a title. Is
there a way to do the above where I do something like:

depCity1.DataTextField = dtReader(0).

I know the above isn''t correct, just trying to find a way to say look at
column 0.

Thanks,

Tom.

推荐答案

托马斯,


昨天几乎同样的问题出现在Adonet新闻组中。

答案在哪里,使用数据绑定,但是我为你做了一个代码示例

你可以使用datareader来实现它。


我希望这有帮助吗?


Cor

\\ \

Dim rdr As SqlDataReader

rdr = cmd.ExecuteReader()

而rdr.Read()

Dim item As New ListItem

item.Text = rdr.GetInt32(0).ToString''表示来自

数据库的整数值

item.Value = rdr.GetString(1)''表示来自的字符串值数据库

DropDownList1.Items.Add(item)

DropDownList2.Items.Add(item)

结束时

///

我希望这有帮助吗?


Cor
Hi Thomas,

Almost the same question was in the Adonet newsgroup yesterday.
The answer where the same, use the databinding, however I made a code sample
for you how you can do it using the datareader.

I hope this helps?

Cor
\\\
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader()
While rdr.Read()
Dim item As New ListItem
item.Text = rdr.GetInt32(0).ToString ''for an integer value from the
database
item.Value = rdr.GetString(1) ''for a string value from the database
DropDownList1.Items.Add(item)
DropDownList2.Items.Add(item)
End While
///
I hope this helps?

Cor


我认为你可以存储将dataReader的数据放入IList容器中,然后你就可以在任何地方使用IList $

" Cor Ligthert" <无********** @ planet.nl> D'è????¢

新闻:u8 ************** @ TK2MSFTNGP09.phx.gbl ...
i think you can store the data of dataReader into a IList container,then you
can user the IList anywhere
"Cor Ligthert" <no**********@planet.nl> D′è????¢
news:u8**************@TK2MSFTNGP09.phx.gbl...
嗨托马斯,

几乎同样的问题是昨天在Adonet新闻组。
答案在哪里,使用数据绑定,但是我为你做了代码
样本你怎么样可以使用datareader做到这一点。

我希望这有帮助吗?

\\\
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader()
而rdr.Read()
Dim item As New ListItem
item.Text = rdr.GetInt32(0).ToString''表示整数值
数据库
item.Value = rdr.GetString(1)''来自数据库的字符串值
DropDownList1.Items.Add(item)
DropDownList2.Items.Add (项目)
结束时
///
我希望这有帮助吗?

Hi Thomas,

Almost the same question was in the Adonet newsgroup yesterday.
The answer where the same, use the databinding, however I made a code sample for you how you can do it using the datareader.

I hope this helps?

Cor
\\\
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader()
While rdr.Read()
Dim item As New ListItem
item.Text = rdr.GetInt32(0).ToString ''for an integer value from the
database
item.Value = rdr.GetString(1) ''for a string value from the database
DropDownList1.Items.Add(item)
DropDownList2.Items.Add(item)
End While
///
I hope this helps?

Cor



你好Coollzh,


我说这个问题昨天已经在adonet组另外,

的答案是使用适配器和数据表,但是在我看来,使用datareader这是最短的

方式(我看到了没有真正的

优势)。


但是使用Ilist解决方案有什么好处,我确实想到了

给出了但是我没有看到任何优势。


Cor
Hi Coollzh,

I said this question has been in the adonet group yesterday too, there the
answer was to use an adapter and a datatable, however this is the shortest
way to do it in my opinion with the datareader (for which I see no real
advantage).

However what is the advantages of using an Ilist solution, I did think of
giving that, however I saw no advantage.

Cor


这篇关于重用DataReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆