Я должен выполнить запрос SQL, используя текстовое значение в метке, а затем выполнить этот запрос и привязать данные к сетке. Вот мой код в VB.net
Dim myConnection As SqlConnection = New SqlConnection
Dim ad As New SqlDataAdapter
Dim details As New DataSet
Dim detailcmd As New SqlCommand("select student_name,student_id from students where student_name = '" + snamelabel.Text + "'", myConnection)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ad.SelectCommand = detailcmd
myConnection.ConnectionString = "Data Source=USER-PC\SQLEXPRESS;Initial Catalog=students;Integrated Security=True"
myConnection.Open()
ad.Fill(details, "Details")
myConnection.Close()
DetailGridView.DataSource = details
DetailGridView.DataBind()
End Sub
Я получаю следующее сообщение об ошибке для SqlCommand --->
Object reference not set to an instance of an object.
Является ли привязка данных для вида сетки правильной?
Есть идеи?