我的显示按钮代码如下.但是它给出了错误消息msg,因为它是朋友,因此无法访问dr [英] hiiiiii my code for display button is below. but it give error msg that dr is not accessible as it is a friend
本文介绍了我的显示按钮代码如下.但是它给出了错误消息msg,因为它是朋友,因此无法访问dr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim cmd As New SqlCommand
cmd.CommandText = "select * from tbsumeet1"
cmd.Connection = con
Dim dr As New SqlDataReader
dr = cmd.ExecuteReader
ListBox1.DataTextField = "ename"
ListBox1.DataValueField = "en"
ListBox1.DataSource = dr
ListBox1.DataBind()
推荐答案
在定义数据读取器时删除关键字New
.这是因为ExecuteReader
在内部执行New
并返回创建的DataReader
.因此,无需直接创建DataReader的实例.
因此,请更改此内容:
Remove the keywordNew
while defining datareader. This is becauseExecuteReader
doesNew
internally and returnsDataReader
created. So, no need to directly create the instance of DataReader.
So, change this:
Dim dr As New SqlDataReader
至:
to:
Dim dr As SqlDataReader
Refer: Similar issue discussed[^]
这篇关于我的显示按钮代码如下.但是它给出了错误消息msg,因为它是朋友,因此无法访问dr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文