Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

how to insert sms from the sim card to the database using AT command in vb.net?

$
0
0
Am doing the project which require sms to be retrieved from the database i failed to insert sms in the database because it is in long format i mean it is not separated as message, sender, received time and so. Am using AT COMMAND and visual basics language. PLEASE I GIVE ME YOUR HELP IF YOU HAVE ANY IDEA..



Private Sub btnread_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnread.Click
        Dim data As String
        If SerialPortsms.IsOpen() Then
            SerialPortsms.Write("AT" & vbCrLf)
            'SerialPortsms.Write("AT+CMGF=1" & vbCrLf)
            SerialPortsms.Write("AT+CMGF=1" & vbCrLf)
            ' Use character set "PCCP437"
            SerialPortsms.Write("AT+CSCS=""PCCP437""" & vbCrLf)
            ' Select SIM storage
            SerialPortsms.Write("AT+CPMS=""SM""" & vbCrLf)
            SerialPortsms.Write("AT+CMGL=""all""" & vbCrLf)
            'SerialPort1.Write(Message & Chr(26))
            rtread.Text = SerialPortsms.ReadExisting()
            data = SerialPortsms.ReadExisting
            query = "INSERT INTO inbox (sender, receiver, msg, senttime, receivedtime, msgtype, operator) VALUES ('$originator','$recipient',(data),'$senttime','$receivedtime','$messagetype','$operatornames')"


            Try
                con = database.open()
                If con IsNot Nothing Then
                    com = New SqlCommand(query, con)
                    com.ExecuteNonQuery()

                    MsgBox("added")

                End If
            Catch ex As Exception
                MsgBox("could not insert values into database" & vbNewLine & ex.Message)
            End Try

        Else
            MsgBox("Port not available")

        End If
    End Sub

Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>