Someone please help. I'm using VB 2008 express.
Imports System.Data.OleDb
Imports System.Text
Imports System.Data
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents serialPort As New IO.Ports.SerialPort
Dim receivedData As String
'Dim MySoundPlayer As New System.Media.SoundPlayer
Dim da As OleDbDataAdapter
Dim connection As OleDbConnection
'Dim bsource As BindingSource = New BindingSource()
Dim ds As DataSet
Dim str As String
Dim dsNewRow As DataRow
Private Sub cbLog_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbLog.CheckedChanged
Timer1.Enabled = True
Try
'connection for database
Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Amos\Data\unisim\Capstone project\Database\SMSDataCenter.accdb; Persist Security Info=False;"
connection = New OleDbConnection(ConnectionString)
str = "SELECT * FROM SMSLog"
da = New OleDbDataAdapter(str, connection)
connection.Open()
ds = New DataSet()
Dim commandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(da)
da.Fill(ds, "SMSLog")
connection.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'set command message format to text mode
serialPort.Write("AT+CMGL=""REC UNREAD""" & vbCrLf)
receivedData = serialPort.ReadExisting()
If Not (receivedData = "") Then
Trim(txtDataReceived.Text)
With txtDataReceived
.AppendText(receivedData)
.ScrollToCaret()
End With
If (receivedData.IndexOf("ALARM") <> -1) Then
Dim tgt As String = receivedData
'Dim HPnum As String = tgt.Substring(26, 11)
dsNewRow = ds.Tables("SMSLog").NewRow()
dsNewRow.Item("TimeStamp") = System.DateTime.Now
'dsNewRow.Item("Mobile_Number") = HPnum
dsNewRow.Item("Status") = "ALARM"
ds.Tables("SMSLog").Rows.Add(dsNewRow)
da.Update(ds, "SMSLog")
End If
End If
End Sub
End Class

New Topic/Question
Reply




MultiQuote



|