Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

this is a VB Express 2010 question 2

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
So I guess this is the correct forum?
I am trying to scan a bar code into a text box and then populate a grid view with the results of the SQL statement.
Using Access I would use the "after update" event of the text box and put the code there. So where do I put the code in VB '10?
When I scan the barcode while the cursor is blinking in the text box it puts the number in the text box. The Scanner is programmed to also send an "Enter" key sequence. so Access would make it tab over to the next Tab stop. Not VB '10.
in VB '10 I can see the number in the text box, but it ignores the Enter key. In other words it just stays in that box. Scanning a barcare into Notepad it does jump to the next line below after a scan which is normal.

I hard coded the SQL statement to make sure it in fact returned a valid recordset to the grid and it does. but I can't make it work scanning a bar code. I have done this same thing in a myriad of programs over the years so I know what to expect.
I can't even seem to send the value of one text box to another either? I though it was not working since there was only one textbox on the form and it had no place to go. Nope
Code:
   Private Sub txtScan_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtScan.TextChanged
        Me.TextBox1 = Me.txtScan
        Dim connectionString As String
        Dim cnn As SqlConnection

        connectionString = "Data Source=P4SCREAMER\SQLEXPRESS;Initial Catalog=StudentPickup;Integrated Security=SSPI;"
        cnn = New SqlConnection(connectionString)

        Try
            cnn.Open()
            Dim query As String
            query = "select * from dbo.PickupScans where RFIDTag = '" & Me.txtScan.ToString & "'"
            'query = "select * from dbo.PickupScans where RFIDTag = '810326010764'"  < this works hardcoded

            Dim da As New SqlDataAdapter
            Dim dt As New DataTable
            'dt.Clear()
            da.SelectCommand = New SqlCommand(query, cnn)
            da.Fill(dt)
            DataGridView1.DataSource = dt
            
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Information, "Can not open connection ! ")

        End Try
        cnn.Close()
    End Sub

Also if I put in a breakpoint after the "query" variable it does not have the barcode number, it has this? whatever it means?
"select * from dbo.PickupScans where RFIDTag = 'System.Windows.Forms.TextBox, Text: 8'" So I think it see teh first digit of the number and fires the TextChanged event before the rest of the number is in?

I would expect to see something like:
select * from dbo.PickupScans where RFIDTag = '810326010764' or I did in Access, VB6 and others.

So which Textbox event do I need to use for the barcode scanner and have it put the entire number?



DougP
 
Change:

Me.txtScan.ToString

To:

Me.txtScan.Text

With Access and VB6, the Text is the default property of a text box, so you did not need to put txtScan.Text (even though you should have). The Text property is already a string so you don't need to add .ToString.



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks super fast response George,
I was looking for .value and forgot about .text

So when I scan it now works but I get a bonk since it is getting an Enter key press after it. I know in Access I could set the behavior after ? (I forgot where it is in Access 2007?) or something. is that available in here VB '10 anywhere?

I have seen too much change in 2 decades of VB I can't keep it straight anymore. I stared in VB1 in 1992 as soon as I got wind of it.

Is there a 2010 forum or is this the right place?
maybe they should rename it
VB.NET 2002- and beyond Forum



DougP
 
I'm not the best at vb2010, but I think this will work for you:

Code:
Private Sub txtScan_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtScan.KeyPress
  If e.KeyChar = ControlChars.Cr Then
    e.Handled = True
  End If
End Sub

Basically, check the keyPress event and set e.Handled to true if it's a CR.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top