如何查看标签而不是listview的数据? [英] How to view data to a label instead of listview?

查看:72
本文介绍了如何查看标签而不是listview的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题并且没有显示任何内容..请检查我的代码出错了什么..谢谢!



 私有  Sub  index_Load( ByVal  sender 作为系统。对象 ByVal  e  As  System.EventArgs)句柄  MyBase  .Load 
con.Open()
Dim qwerty As String = 从tbl_funeral中选择concat(name,'at',funtime),其中date_burial =' & DateTime.Now.ToString( MMMM dd,yyyy)& '
Dim cmd1 作为 MySqlCommand(qwerty,con)
Dim datan As MySqlDataReader = cmd1.ExecuteReader
' while datan.Read
Label3.Text = datan.ToString()
con.Close()
' 结束时
结束 Sub





我的尝试:



它运行(当我删除注释(而datan.Read)....)但是,它显示像MySql.Data.MySqlClient ....

解决方案

 如果 dat an.Read 然后 
Label3.Text = datan [ 0 ]。ToString()
结束 如果
con.Close()





我不知道vb.net,你可能需要datan [1]而不是datan [0],我认为vb.net数组从1开始而不是0。该代码获取结果集的第一列。如前所述,如果您选择一个普通字段,您可能会使用字段名,但是您正在执行一个函数而不是选择一个字段,因此它要么没有名字,要么没有任何名称(我不知道) MySQL要么:))


你需要读取列而不是读者。



所以,这应该是... 。

 如果 reader.HasRows 那么 
reader.Read()
Label3.Text = datan [< span class =code-string> ColumnName]。ToString()
Loop



如果查询执行返回的行数更多,则label将显示最后一行的列值。所以,这取决于你。



如果你只想返回一个值,那么使用 ExecuteScalar 而不是阅读器。


I have a problem and it displays nothing.. Kindly check my code what made wrong.. Thanks!

Private Sub index_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       con.Open()
       Dim qwerty As String = "Select concat (name,' at ',funtime) from tbl_funeral where date_burial='" & DateTime.Now.ToString("MMMM dd,yyyy") & "'"
       Dim cmd1 As New MySqlCommand(qwerty, con)
       Dim datan As MySqlDataReader = cmd1.ExecuteReader
       ' While datan.Read
       Label3.Text = datan.ToString()
       con.Close()
       'End While
   End Sub



What I have tried:

It runs (when i removed the comment (while datan.Read) ....) however, it displays like MySql.Data.MySqlClient....

解决方案

If datan.Read Then
       Label3.Text = datan[0].ToString()
End If
con.Close()



I don't know vb.net, you might need datan[1] instead of datan[0], I think vb.net arrays start at 1 rather than 0. That code is getting the first column of the result set. As said before, if you were selecting a normal field you'd probably use the fieldname, but you're executing a function rather than selecting a field so it'll either have no name, or an arbitrary one (I don't know MySQL either :) )


You need to read the column instead of the reader.

So, this should be...

If reader.HasRows Then
Do While reader.Read()
    Label3.Text = datan["ColumnName"].ToString()
Loop


If you have more rows returned by the query execution, then label will show the last row's column value. So, it's up to you.

If you want to return only one value, then use ExecuteScalar instead of Reader.


这篇关于如何查看标签而不是listview的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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