VB.NET SQL Example: How to send SMS in VB.NET using SQL database


/ Published in: VB.NET
Save to your folder(s)

I thought I share this code snippet because I find this way of SMS sending an easy solution. I believe that even beginners can implement this VB.NET SQL SMS application, but I think some extent of perfection in the SMS technology is required for better understanding. Okay, let’s jump right in the middle of the project that allows you to send and receive SMS through database tables by using your own VB.NET application.

Project information:

• Language: VB.NET
• Level: Intermediate
• IDE: Microsoft Visual Studio
• Database server: MS SQL, MS SQL Express, MySQL, Access, Oracle, etc. I used MySQL (http://www.mysql.com/).
• Special prerequisites: .NET Framework (http://www.microsoft.com/hu-hu/download/details.aspx?id=17851), SMS Gateway (in order to let your PC to send/receive SMS transmissions to/from a telecommunications network). I used Ozeki NG (www.ozekisms.com).

Project description:

First of all, you need to create the necessary database tables: one for the outgoing messages, and another one for the incoming messages. The snippet shows my MySQL commands, but it can be changed of course depending on the database server you use. In order to be able to use your database you need to connect it to your SMS gateway, then you can insert an SMS into the table of the outgoing messages by using an SQL INSERT command. To execute this command, you need to connect to the database by using the myConnection.Open() method. Thereafter insert the message into the database ( mySqlCommand.ExecuteNonQuery() ), then close the database connection ( myConnection.Close() ). That's all there is to it! It wasn't that black magic, was it?


Copy this code and paste it in your HTML
  1. � MySQL commands for creating database tables
  2.  
  3. � CREATE TABLE ozekimessagein (
  4. � id int IDENTITY (1,1),
  5. � sender varchar(30),
  6. � receiver varchar(30),
  7. � msg nvarchar(160),
  8. � senttime varchar(100),
  9. � receivedtime varchar(100),
  10. � operator varchar(30),
  11. � msgtype varchar(30),
  12. � reference varchar(30),
  13. �);
  14. � CREATE TABLE ozekimessageout (
  15. � id int IDENTITY (1,1),
  16. � sender varchar(30),
  17. � receiver varchar(30),
  18. � msg nvarchar(160),
  19. � senttime varchar(100),
  20. � receivedtime varchar(100),
  21. � operator varchar(100),
  22. � msgtype varchar(30),
  23. � reference varchar(30),
  24. � status varchar(30),
  25. � errormsg varchar(250)
  26. �);
  27.  
  28. � VB.NET source code
  29.  
  30. Imports System
  31. Imports System.Data
  32. Imports System.Data.SqlClient
  33.  
  34. Public Class Form1
  35.  
  36. Private Sub bSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSend.Click
  37. Try
  38. Dim dbUsername As String = "ozekiuser"
  39. Dim dbPassword As String = "ozekipass"
  40. Dim database As String = "ozeki"
  41.  
  42. Dim myConnection As New SqlConnection("Server=.\SQLEXPRESS;User ID=" _
  43. & dbUsername _
  44. & ";password=" _
  45. & dbPassword _
  46. & ";Database=" _
  47. & database _
  48. & ";Persist Security Info=True")
  49.  
  50.  
  51. Dim mySqlQuery As String = "INSERT INTO ozekimessageout (receiver,msg,status) " _
  52. & "VALUES ('" & tbReceiver.Text & "', '" & tbMessage.Text & "', 'send');"
  53.  
  54. Dim mySqlCommand As New SqlCommand(mySqlQuery, myConnection)
  55.  
  56. myConnection.Open()
  57.  
  58. mySqlCommand.ExecuteNonQuery()
  59.  
  60. myConnection.Close()
  61.  
  62.  
  63. Catch ex As Exception
  64. MessageBox.Show(ex.Message)
  65. End Try
  66.  
  67.  
  68.  
  69.  
  70.  
  71. End Sub
  72. End Class

URL: http://www.ozekisms.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.