hi ppl i need bit of help in my vb coding.

I have a publish data onto datagrid and allow user to search for specific record by inputting no. everything going fine. however i was unable to inform the user if there is no matching record found. i tried to use following code (last elseif part). but it doesn't work in that way. any help ??? thanks in advance


Dim a As String
For i As Integer = 0 To DataGridView1.Rows.Count - 1
a = DataGridView1.Rows(i).Cells(0).Value

If a = textbox1.Text Then

'fill up data into textboxes

ElseIf textbox1.Text = "" Then
MsgBox("Please Scan card to Proceed")
textbox1.Focus()
Exit For

Elseif a <> textbox1.text then
MsgBox("No Record found")
Exit For


End If

Next

Recommended Answers

All 5 Replies

hello !
you are getting records from db , and then want to search records from the grid ? can you please rephrase it

check this out

Dim i As Integer
        Dim a As Integer
        Dim isfound As Boolean
        For i = 0 To DataGridView1.Rows.Count - 1
            a = Val(ListBox1.Items(i))
            a = DataGridView1.Item("columnindex", i).Value.ToString '
            If txtSearch.Text = a Then
                isfound = True
                Exit For
            Else
                isfound = False
            End If
        Next
        If isfound = True Then
            MsgBox("found")
        Else
            MsgBox("not found")
        End If

if this code helps you and solve your prob ,please mark your thread solved and vote me up :)

Regards

Please clarify your problem....

Thanks mate. i changed my coding in following way and able to get what i want. thanks a lot. :)

Dim a As String
Dim isfound As Boolean

For i As Integer = 0 To DataGridView1.Rows.Count - 1
a = DataGridView1.Rows(i).Cells(0).Value

If a = textbox1.Text Then

'fill up data into textboxes

isfound = True
Exit For


ElseIf textbox1.Text = "" Then
MsgBox("Please Scan card to Proceed")
textbox1.Focus()
Exit For

else

isfound = False

End If

Next

If isfound = False Then
MsgBox("No Record found", vbExclamation)

End If

please mark this thread solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.