Hi guys,
I am trying to extract received sms messages from my gsm modem and inserting them into sql database, but i am getting a lot of inconsistency errors due to the messages not coming in properly when i click on a button.
i used the substring method in vb.net to grab the message string but it is inconsistent due to the "ok" returned by the modem. Sometimes one time sometimes two. So the substring extracted often gets mixed up.
So now i am thinking of how to extract the sms message body contents only and inserting them to sql database.
the result i got from past try out is per attached.
I am using the AT command set in this prog.
below is my code
hope someone is able to help me. Thnks in advance.
regards,
Charles
I am trying to extract received sms messages from my gsm modem and inserting them into sql database, but i am getting a lot of inconsistency errors due to the messages not coming in properly when i click on a button.
i used the substring method in vb.net to grab the message string but it is inconsistent due to the "ok" returned by the modem. Sometimes one time sometimes two. So the substring extracted often gets mixed up.
So now i am thinking of how to extract the sms message body contents only and inserting them to sql database.
the result i got from past try out is per attached.
I am using the AT command set in this prog.
below is my code
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'testing of AT command
'Dim rec As String = "REC UNREAD"
serialPort.WriteLine("AT+CMGR=1" & vbCrLf) 'send command over
receivedData = serialPort.ReadExisting() 'read command response
TextBox1.AppendText(receivedData)
'MsgBox(receivedData)
TextBox1.ScrollToCaret()
'connect to database
Dim sql As String
Dim connectionString As String = "Data Source=TEMASEK-8EA594C\SQLEXPRESS;Initial Catalog=sms compare;" & "Integrated Security=SSPI;"
conn = New SqlConnection(connectionString)
sql = "SELECT * FROM record"
da = New SqlDataAdapter(sql, conn)
conn.Open()
ds = New DataSet()
Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
da.Fill(ds, "record")
bsource.DataSource = ds.Tables("record")
' DataGridView2.DataSource = bsource
conn.Close()
Dim tgt As String = Trim(receivedData)
Dim pnum As String
'MsgBox(pnum)
Dim msg As String
'MsgBox(msg)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("record").NewRow()
' dsNewRow.Item("PhoneNumber") = pnum
dsNewRow.Item("sms") = pnum
ds.Tables("record").Rows.Add(dsNewRow)
da.Update(ds, "record")
MsgBox("Phone Number and Message added to the Database")
End Sub
hope someone is able to help me. Thnks in advance.
regards,
Charles