Bryan Seisay Bryan Seisay - 13 days ago 9
Vb.net Question

How do i display a message box if the textbox is empty after a search

I'm trying to display a message box if no data is pulled from the database at the end of the comparison



Private Sub submitbutton_Click(sender As Object,
e As EventArgs) Handles submitbutton.Click myConnection.Open()
tutorboxr.Clear()
compboxr.Clear()
Dim str As String
Dim etr As String
str="SELECT * FROM 2014Results WHERE (Competitor = '" & Competitor.Text &"')"
etr="SELECT * FROM 2014Results WHERE (Event = '" & EventBox.Text &"')"

Dim cmd As OleDbCommand=New OleDbCommand(str,
myConnection)

Dim emd As OleDbCommand=New OleDbCommand(etr,
myConnection) dr=cmd.ExecuteReader

While dr.Read()
compboxr.Text=dr("Rank").ToString
textbox.Text=dr("Reg").ToString

If Competitor.Text="" Then MessageBox.Show("This student wasn't a ranking placeholder!",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
End While myConnection.Close()

If Competitor.Text="" Then MessageBox.Show("Please enter a students name",
"No entry",
MessageBoxButtons.OK,
MessageBoxIcon.Error) With Competitor .Focus() .SelectAll() End With Exit Sub
End If
End Sub





I receive this error:


Overload resolution failed because no accessible 'Show' can be called without a narrowing conversion: : Argument matching parameter narrows from 'MessageBoxButtons' to 'String'. : Argument matching parameter narrows from to 'MessageBoxButtons'. : Argument matching parameter narrows from 'String' to. : Argument matching parameter 'text' narrows from 'MessageBoxButtons' to 'String'. : Argument matching parameter narrows from to 'String'.

Answer

Looks like you are missing a parameter on the first MessageBox.Show call:

If Competitor.Text="" Then
    MessageBox.Show("This student wasn't a ranking placeholder!",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error) 
End If

It should be like the second call:

If Competitor.Text="" Then
    MessageBox.Show("This student wasn't a ranking placeholder!",
                    "** a caption here **",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error) 
End If
Comments