hello
can u help me to store data from vb.net to access...right now i get the data from com port. and i want the data to be save in the access...below is the sample code...
Public Class frmSerialPortExample
'----------------------------------------------------------------------------------------------------------
'Purpose: Allow for data recieve event to update text box on different thread
'----------------------------------------------------------------------------------------------------------
Public Delegate Sub myDelegate()
'----------------------------------------------------------------------------------------------------------
'Purpose: Close and exit
'----------------------------------------------------------------------------------------------------------
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
'----------------------------------------------------------------------------------------------------------
'Purpose: Load Form
'----------------------------------------------------------------------------------------------------------
Private Sub frmSerialPortExample_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i As Integer = 0 To My.Computer.Ports.SerialPortNames.Count - 1
cboCommPorts.Items.Add(My.Computer.Ports.SerialPortNames(i))
Next
cmdDisconnect.Enabled = False
End Sub
'----------------------------------------------------------------------------------------------------------
'Purpose: Connect to comm port
'----------------------------------------------------------------------------------------------------------
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
Try
With SerialPort1
.PortName = cboCommPorts.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
SerialPort1.Open()
lblMessage.Text = SerialPort1.PortName & " connected"
cmdDisconnect.Enabled = True
cmdConnect.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'----------------------------------------------------------------------------------------------------------
'Purpose: Disconnect from comm port
'----------------------------------------------------------------------------------------------------------
Private Sub cmdDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisconnect.Click
Try
SerialPort1.Close()
lblMessage.Text = SerialPort1.PortName & " disconnected"
cmdDisconnect.Enabled = False
cmdConnect.Enabled = True
Catch ex As Exception
End Try
End Sub
'----------------------------------------------------------------------------------------------------------
'Purpose: Send message to selected comm port
'----------------------------------------------------------------------------------------------------------
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Try
SerialPort1.Write(txtTextToSend.Text & vbCrLf)
With txtDataRecieved
.SelectionColor = Color.Black
.AppendText(txtTextToSend.Text & vbCrLf)
.ScrollToCaret()
End With
txtTextToSend.Text = String.Empty
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'----------------------------------------------------------------------------------------------------------
'Purpose: Update text box with data recieved from comm port
'----------------------------------------------------------------------------------------------------------
Public Sub updateTextBox()
With txtDataRecieved
.Font = New Font("Garamond", 12.0!, FontStyle.Bold)
.SelectionColor = Color.Red
.AppendText(SerialPort1.ReadExisting)
.ScrollToCaret()
End With
End Sub
'----------------------------------------------------------------------------------------------------------
'Purpose: Receive data
'----------------------------------------------------------------------------------------------------------
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
txtDataRecieved.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) ', New Object()
End Sub
End Class
the string of data which i get from com port are like this ' $HUB0, 30.9C, 3.5, 000, N#'
and i don't want to store the data into one column...but separate it into 5 column per data...
can u help me please..because i need to submit my task to lecturer next week..