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".
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 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.