0

我想在查询中的DataGridViewwhere 子句中显示选择查询的结果。条件在标签的值中指定。IE

select * 
from hospital_details 
where location_name= '" & Label6.Text & "'"

以下是代码

Public Sub fill()

    Try
        createConnection()
        da = New SqlDataAdapter
        Dim c As String
        c = Label6.Text
        comm.CommandText = "select * from hospital_details where location_name= '" & Label6.Text & "'"
        da.SelectCommand = comm
        da.Fill(ds, "hospital_details")
        DataGridView2.DataSource = ds.Tables(0)
        DataGridView2.DataMember = "hospital_details"
        DataGridView2.ReadOnly = True

    Catch ex As Exception

        MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")

    End Try

End Sub

但它的显示错误:NullException

4

1 回答 1

0

您可以从 sql server 加载数据,点击链接 http://mssqlguid.blogspot.in/2013/07/how-to-load-data-into-datagridview-from.html

于 2013-07-25T12:56:54.217 回答