1.11M Members

Retrieve multiple rows form database to datagridview with same id

 
0
 

Hi all. I need your help. Iam using vb.net 2010 and sql server 2008. I have problem when retrieve multiple rows from database to datagridview. All rows have the same identification number(patient registration number).I have problem in loop to show the all rows in datagridview. Pleaase anyone knows that help me.
Thanks in advance.
Here is my code

 Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim i As Integer
        dgvPatienttrack.Rows.Clear()
        If txtParegno.Text = "" Then
            MessageBox.Show("Enter a patient registration number!")
            txtParegno.Focus()
        Else

            secommand = New SqlCommand("SELECT * FROM tblPatienttracking WHERE Pa_Reg_No='" & txtParegno.Text & "'", Cconnect)
            Cconnect.Open()
            secommand.Connection = Cconnect
            seadapter.SelectCommand = secommand
            seadapter.Fill(sedataset, "tblPatienttracking")
            Dim count = sedataset.Tables(0).Rows.Count
            If count = 0 Then
                MessageBox.Show("Patient visit records not found!")
            End If

            MessageBox.Show("Patient record found!")

            For i = 0 To Me.dgvPatienttrack.RowCount - 1
                While count > 0
                    ins = 0
                    count = 1
                    Me.dgvPatienttrack.Rows(i).Cells(0).Value = sedataset.Tables("tblPatienttracking").Rows(ins).Item(1)
                    Me.dgvPatienttrack.Rows(i).Cells(1).Value = sedataset.Tables("tblPatienttracking").Rows(ins).Item(2)
                    Me.dgvPatienttrack.Rows(i).Cells(2).Value = sedataset.Tables("tblPatienttracking").Rows(ins).Item(3)
                    Me.dgvPatienttrack.Rows(i).Cells(3).Value = sedataset.Tables("tblPatienttracking").Rows(ins).Item(4)
                    Me.dgvPatienttrack.Rows(i).Cells(4).Value = sedataset.Tables("tblPatienttracking").Rows(ins).Item(5)
                    Me.dgvPatienttrack.Rows(i).Cells(5).Value = sedataset.Tables("tblPatienttracking").Rows(ins).Item(6)

                    ins += 1
                    count += 1
                End While
            Next i




            Cconnect.Close()
        End If

    End Sub
 
0
 

Private Sub btnSearch_Click ( ByVal sender As System . Object , ByVal e As System . EventArgs ) Handles btnSearch . Click
Dim i As Integer
dgvPatienttrack . Rows . Clear ()
If txtParegno . Text = "" Then
MessageBox . Show ( "Enter a patient registration number!" )
txtParegno . Focus ()
secommand = New SqlCommand ( "SELECT * FROM tblPatienttracking " , Cconnect )
Else
secommand = New SqlCommand ( "SELECT * FROM tblPatienttracking WHERE Pa_Reg_No='" & txtParegno . Text & "'" , Cconnect )

End if
Cconnect . Open ()
secommand . Connection = Cconnect
seadapter . SelectCommand = secommand
seadapter . Fill ( sedataset , "tblPatienttracking" )
Dim count = sedataset . Tables ( 0 ). Rows . Count
If count = 0 Then
MessageBox . Show ( "Patient visit records not found!" )
MessageBox . Show ( "Patient record found!" )
For i = 0 To Me . dgvPatienttrack . RowCount - 1
While count > 0
ins = 0
count = 1
Me . dgvPatienttrack . Rows ( i ). Cells ( 0 ). Value = sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 1 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 1 ). Value = sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 2 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 2 ). Value = sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 3 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 3 ). Value = sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 4 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 4 ). Value = sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 5 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 5 ). Value = sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 6 )
ins += 1
count += 1
End While
Next i
Cconnect . Close ()
End If
End Sub

 
0
 

Private Sub btnSearch_Click ( ByVal sender As System . Object , ByVal e As System . EventArgs ) Handles btnSearch . Click
Dim i As Integer
dgvPatienttrack . Rows . Clear ()
If txtParegno . Text = "" Then
MessageBox . Show ( "Enter a patient registration number!" )
txtParegno . Focus ()
secommand = New SqlCommand ( "SELECT * FROM tblPatienttracking " , Cconnect )
Else
secommand = New SqlCommand ( "SELECT * FROM tblPatienttracking WHERE Pa_Reg_No='" & txtParegno . Text & "'" , Cconnect )
End if
Cconnect . Open ()
secommand . Connection = Cconnect
seadapter . SelectCommand = secommand
seadapter . Fill ( sedataset , "tblPatienttracking")
Dim count = sedataset . Tables ( 0 ). Rows . Count
If count = 0 Then
MessageBox . Show ( "Patient visit records not found!" )

End if
MessageBox . Show ( "Patient record found!" )
For i = 0 To Me . dgvPatienttrack . RowCount - 1
While count > 0
ins = 0
count = 1
Me . dgvPatienttrack . Rows ( i ). Cells ( 0 ). Value= sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 1 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 1 ). Value= sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 2 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 2 ). Value= sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 3 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 3 ). Value= sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 4 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 4 ). Value= sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 5 )
Me . dgvPatienttrack . Rows ( i ). Cells ( 5 ). Value= sedataset . Tables ( "tblPatienttracking" ). Rows ( ins ). Item ( 6 )
ins += 1
count += 1
End While
Next i
Cconnect . Close ()
End Sub

 
0
 

Try this second one

 
0
 

where is ins declaration

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article