0

DataGridViewクエリ内のwith where 句でselect クエリの結果を表示したい。条件は、ラベルの値で指定されます。すなわち

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 に答える