首先让我说我是vb的新手,就脚本而言,我只是真的使用过matlab。
无论如何,我正在vb2010中编写一个脚本,允许我从mysql读写。一切都在测试模式。我能够让它读取和写入,但是对于下一阶段的努力,我希望脚本能够在从扫描仪读取条形码后读取mysql。一旦它可以做到这一点,我相信我可以完成代码。
就rf扫描程序脚本而言,我甚至不知道从哪里开始。
这是我已经拥有的:
Imports MySql.Data.MySqlClient
Imports System.Data
Public Class TEST
Inherits System.Windows.Forms.Form
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim reader As MySqlDataReader
Dim par As MySqlParameter
Dim result As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox4.Text = Now.ToString()
'Dim str As String
'Dim num As Integer
'str = ComboBox1.Text
'num = CInt(str)
conn = New MySqlConnection
conn.ConnectionString = "Server=localhost;Database=test;Uid=root;Pwd=****;"
Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
myCommand.CommandText = "INSERT INTO this (workorderno, Datein, operator) values ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & combobox1.Text & "')"
myCommand.Connection = conn
myCommand.ExecuteNonQuery()
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
Try
conn.Open()
MessageBox.Show("Connection established")
myCommand = New MySqlCommand("Select number From this Where workorderno = @textbox1.text", conn)
par = New MySqlParameter
par.ParameterName = "textbox1.text"
par.Value = TextBox1.Text
myCommand.Parameters.Add(par)
reader = myCommand.ExecuteReader()
If reader.Read() Then
result = reader.GetString(0)
End If
''//output to textbox
TextBox3.Text = result
conn.Close()
Catch ex As Exception
Finally
conn.Dispose()
End Try
End Sub
答案 0 :(得分:0)
假设您的扫描仪通过串行接口与您的计算机通信,您的程序可以通过COM端口读取它,您可以先将SerialPort
添加到您的项目中,输入Port Name
,我猜您可以在“设备管理器”中找到它。然后,您可以开始打开端口,从SerialPortDataDidReceived
操作添加SerialPort
功能。
作为参考,来自youtube的视频应该会帮助你:]
Visual Basic Serial COM Port Tutorial (Visual Studio 2010)
您应该找到一些带有关键字Serial Port
的教程,希望这可以提供帮助! =]