Link to home
Create AccountLog in
Avatar of mdoyon
mdoyon

asked on

How do I get an image to show from a database in VB 2008 Barcode Blackjack

I am trying to create a blackjack game for a handheld scanning computer.  I want the scanner to scan the barcode with the value of the card.  As of right now I am unable to get the image of the card to appear once the barcode has been scanned. After running the program in debug I have noticed it goes through the keydown event but does not go through the load card yet there are no errors.  Here is what I have so far...


    Private Sub Code1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Code1.KeyDown
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
            If Not (LoadCard(Code1.Text, PlrCard1)) Then
                MsgBox("That's not a card I know.")
                Code1.Focus()
                Code1.SelectAll()
            Else
                WelcomeLabel.Visible = False
                PlrCard1.Visible = True
                Code2.Text = ""
                Code2.Focus()
            End If

     
                   
    Private Function LoadCard(ByVal Code As String, ByRef CurrentCard As PictureBox) As Boolean

        ' Create a connection to the Mobile SQL database
        Dim Conn As New SqlCeConnection
        Conn.ConnectionString = "Data Source =""Program Files\PokerData.sdf"""
        Conn.CreateCommand()

        ' Check if the DataKey exists
        Dim Cmd As New SqlCeCommand("Select Count(*) From Cards Where CardCode = @DataKey")
        Cmd.CommandType = CommandType.Text
        Cmd.Parameters.Add("@DataKey", SqlDbType.NVarChar)
        Cmd.Parameters("@DataKey").Value = Code
        Cmd.Connection = Conn
        Conn.Open()
        Dim Counter As Integer = Cmd.ExecuteScalar()

        If Counter > 0 Then
            ' Store this image
            Cmd.CommandText = "Select CardImage From Cards Where CardCode = @DataKey"
            Cmd.CommandType = CommandType.Text
            Cmd.Parameters("@DataKey").Value = Code
            Dim bitmapBytes As Byte()
            bitmapBytes = Cmd.ExecuteScalar()

            If bitmapBytes.Length > 0 Then
                Dim stream As MemoryStream = New MemoryStream(bitmapBytes, True)
                stream.Write(bitmapBytes, 0, bitmapBytes.Length)
                Dim BitMapImage As New Bitmap(stream)
                CurrentCard.Image = BitMapImage
                ' Close Connection
                Cmd.Dispose()
                ' Conn.Close()
                Conn.Dispose()
                Return True
            Else
                CurrentCard.Image = Nothing
                ' Close Connection
                Cmd.Dispose()
                ' Conn.Close()
                Conn.Dispose()
                Return True
                Return False
            End If
        Else
            CurrentCard.Image = Nothing
            Return False
        End If

    End Function


   
Avatar of JonMny
JonMny

if you are hitting tab or enter I dont see why it wouldnt run loadcard function, Is it getting past your first condition?
 If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
Avatar of mdoyon

ASKER

It is getting past my first condition and allowing me to enter the next card value, the images of the cards are just not showing up
ok so it is going to the load card function? if so

this line
    stream.Write(bitmapBytes, 0, bitmapBytes.Length)
might need to be
    stream.Write(bitmapBytes, 0, bitmapBytes.Length-1)

Avatar of mdoyon

ASKER

The cards still aren't showing up
ASKER CERTIFIED SOLUTION
Avatar of JonMny
JonMny

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of mdoyon

ASKER

Thanks for the suggestions I am going to let it sit for a little while and hope something comes to me
ok, if it's still not working you might want to verify that the data that is coming back from the database is a valid picture file.