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
我使用此代码假设SQL中的新命名列将在vb net中读取,但不会读取新命名的列“MonthDates”。
代码有什么问题?请帮忙。提前谢谢!
答案 0 :(得分:0)
你应该在查询后处理连接(在我的例子中使用这样做):
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