我的显示按钮代码如下.但是它给出了错误消息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

查看:65
本文介绍了我的显示按钮代码如下.但是它给出了错误消息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 keyword New while defining datareader. This is because ExecuteReader does New internally and returns DataReader 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屋!

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