1 Replies - 784 Views - Last Post: 05 August 2009 - 10:29 PM Rate Topic: -----

#1 amosyeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-June 09

store and display data

Posted 05 August 2009 - 01:14 AM

I'm having problem displaying and storing data from RS232 to access 2007. I have a PIC demo board that sends SMS via AT commands. I want to grab useful information like phone numbers and status message and store/display to access/richtextbox respectively. Right now every line of AT commands are display. And does not store to access. How do i search for the string with numbers like phone numbers?
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



Is This A Good Question/Topic? 0
  • +

Replies To: store and display data

#2 amosyeo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-June 09

Re: store and display data

Posted 05 August 2009 - 10:29 PM

Any advise? There a error whenever i sent data over RS232 at da.Update(ds, "SMSLog"). Syntax error in INSERT INTO statement.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1