2013-03-25 2 views
0

쿼리의 where 절을 사용하여 DataGridView에 선택 쿼리 결과를 표시하고 싶습니다. 조건은 레이블 값에 지정됩니다. 즉DataGridView의 값 채우기

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 

이다 그러나 그 보여주는 오류 : 당신은 SQL 서버에서 데이터를로드 할 수 있습니다

+1

봐에 SQL 인젝션에 링크를 따라 데이터베이스 해킹을 피하십시오. – pickypg

+0

예외에 관해서는, 그것의 원인이되는 줄을 지적하지 않고 말하기는 어렵지만'c = Label6.Text','da.Fill (ds, "hospital_details") 또는'DataGridView2 .DataSource = ds.Tables (0)'행. 'Label6'이 초기화되지 않았거나,'ds'가 초기화되지 않았거나,'DataGridView2'가 초기화되지 않았지만,'Label6'과'DataGridView2'가 모두 코드 숨김 파일에서 나온 것이라고 상상해 봅니다. 결과가 DATAGRIDEVIEW – pickypg

+0

값이 표시되면 어떻게이 값을 얻을 수 있습니까? – user2206026

답변