|
-
Apr 30th, 2013, 06:14 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to display item not found message box with this code?
I am trying to display a message box if the string entered in the textbox was not found in the database
Also, if the enter button is pressed and the textbox is blank, then a msgbox should say "A value must be entered"
I have tried everything to my knowledge and vb.net does not like it.
Code:
Private Sub ButtonLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLookup.Click
Try
Dbconnect.Open() ' Try Block - Connects To The Database. Displays An Error If It Can't.
Dim DbAdapter As New MySqlDataAdapter("SELECT * FROM Itemlist WHERE Barcode = '" & TextBoxItemInput.Text & "'", Dbconnect)
Dim DbDataSet As New DataSet
DbAdapter.Fill(DbDataSet, "Itemlist")
Dim DbTable As DataTable = DbDataSet.Tables("Itemlist")
For Each row As DataRow In DbTable.Rows
Dim ItemSku As Integer = row("ItemSku").ToString()
Dim ItemName As String = row("ItemName").ToString()
Dim Barcode As String = row("Barcode").ToString()
Dim Price As Decimal = row("Price").ToString()
ItemGridView.Rows.Add(Barcode, ItemName, 1, Price, Price)
LabelStatus.Text = "Item Added"
LineDisplay.ClearText()
LineDisplay.DisplayText(ItemName & " $" & Price)
ItemGridView.ClearSelection()
TextBoxItemInput.Clear()
Next
-
Apr 30th, 2013, 07:12 AM
#2
Re: How to display item not found message box with this code?
Fill will return the number of records retrieve, so you simply test whether that's zero or not. By the way, why create a DataSet if all you want is a DataTable? Why not just create a DataTable?
Code:
If myDataAdapter.Fill(myDataTable) = 0 Then
'No matching rows found.
Else
'Yes matching rows found.
End If
-
May 2nd, 2013, 04:38 AM
#3
Thread Starter
Addicted Member
Re: How to display item not found message box with this code?
What does this mean. This is coming from the next statement.
"Collection was modified; enumeration operation might not execute."
I put it at the top as well, But it is add in a dgv row twice
-
May 2nd, 2013, 06:20 AM
#4
Re: How to display item not found message box with this code?
A For Each loop requires that the list that you enumerate is not altered until the loop ends.
-
May 2nd, 2013, 08:15 PM
#5
Thread Starter
Addicted Member
Re: How to display item not found message box with this code?
I just remembered , that maybe I should put in an Exit For , then then it could go on to the next thing.
It seems to work fine displaying a message box for "Item Found", when I type an actual number that is in the database
But when I type an invalid item number, it never shows the message box for "Item Not Found".
Last edited by jcharles12; May 2nd, 2013 at 08:35 PM.
-
May 2nd, 2013, 08:51 PM
#6
Thread Starter
Addicted Member
Re: How to display item not found message box with this code?
I'm ok now. I just had to organize the code into the right place.
Thank you, jmcilhinney
All is well
-
May 2nd, 2013, 08:51 PM
#7
Re: How to display item not found message box with this code?
Perhaps you could show us the actual code you're talking about.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|