简体   繁体   English

vb.net从新名称sql数据库中获取价值

[英]vb.net getting value from a new name sql database

 Dim cd As SqlCommand = New SqlCommand("select datepart(mm,Birthday) as MonthDates from Information where Name='" & cbname.Text & "'", con)
            Dim reader1 As SqlDataReader = cd.ExecuteReader
            While reader1.Read
                Dim mon As Integer = reader1("MonthDates")
                lblbday.Text = mon

I used this code to assume that the new named column in SQL will be read in vb net but its not reading the new named Column "MonthDates". 我使用此代码假定将在vb net中读取SQL中的新命名列,但不会读取新的命名列“ MonthDates”。

What is wrong with the code? 代码有什么问题? Please help. 请帮忙。 Thank you in advance! 先感谢您!

You should dispose connection after query (in my example USING do this): 您应该在查询后处理连接(在我的示例中使用USING这样做):

Using con As New SqlConnection(....)
    Dim cd As SqlCommand = New SqlCommand("select datepart(mm,Birthday) as MonthDates from Information where Name='" & cbname.Text & "'", con)
    Dim mon As Integer = cd.ExecuteScalar()
    lblbday.Text = mon
End Using

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM