Click here to Skip to main content
15,885,146 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Am working on School Management System,i want to send multiple SMS of student performance to their individual parents.I have stored parents phone numbers on SQL server.I want to retrieve student performance based on parent phones,however my system is not working if sends first SMS with blank data.Below is code am using.

VB
Imports System
Imports System.Data
Imports System.ComponentModel
Imports System.Text
Imports System.Collections.Generic
Imports GsmComm.GsmCommunication
Imports GsmComm.PduConverter
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic


Public Class sendS1results
    Dim pdu As SmsSubmitPdu
    Dim phone, grade, mesg As New ArrayList
    Dim a As Integer
    Private Sub sendS1results_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call loadCbmTerm()

    End Sub
    Public Sub loadCbmTerm()
        With cbmTerm
            .Items.Add("1")
            .Items.Add("2")
            .Items.Add("3")
        End With
    End Sub

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Call send()
    End Sub
    Public Sub send()
        Dim con As New SqlConnection(conString)
        Dim com As New SqlCommand
        Dim dr As SqlDataReader
        Dim dat As New DataTable
        con.Open()
        With com
            .Connection = con
            .CommandType = CommandType.Text
            .CommandText = "select * from vS1Phones"
            dr = com.ExecuteReader
        End With
        While dr.Read
            phone.Add(dr.Item(0))
        End While
        con.Close()
        For Each n In phone
            txtPhone.Text = n
            If con.State = ConnectionState.Closed Then
                con.Open()
            Else
                With com
                    .Connection = con
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "s1Phone"
                    .Parameters.Add("@term", SqlDbType.NChar, 3).Value = cbmTerm.SelectedItem
                    .Parameters.Add("@phone", SqlDbType.NVarChar, 10).Value = txtPhone.Text
                    dr = com.ExecuteReader
                End With
                While dr.Read
                    mesg.Add(dr.Item(0) + dr.Item(1))
                End While
                For Each m In mesg
                    txtMessage.AppendText(m)
                Next
            End If

            'mesg.Clear()
            'txtMessage.Clear()
            Try
                pdu = New SmsSubmitPdu(txtMessage.Text, txtPhone.Text)
                ModemSettings.ms.Open()
                ModemSettings.ms.SendMessage(pdu)
                ModemSettings.ms.Close()
            Catch ex As Exception
                MessageBox.Show("Error when sending SMS")
            End Try

            'txtMessage.Clear()
        Next n
        con.Close()
        'phone.Clear()


    End Sub
Posted
Updated 10-Jun-11 0:24am
v2
Comments
Slacker007 10-Jun-11 6:22am    
Possible school project maybe?
DaveAuld 10-Jun-11 6:24am    
edit: formatting fixed

The problem is here:
VB.NET
If con.State = ConnectionState.Closed Then
  con.Open()
Else
  With com
   ...
End If


The first thing you have to do is check if the connection is closed, and it is. Then you have to open it. The mesg variable is never filled with data.

A simple breakpoint and debug will help you.
 
Share this answer
 
v3
I suggest you follow this Link [^] and try/implement something different.
 
Share this answer
 
v2
Comments
Karwa_Vivek 10-Jun-11 6:44am    
Maybe it can help if you understand the basics.
dfgdfgdf
 
Share this answer
 
Comments
[no name] 19-Sep-14 9:40am    
Why did you wait almost 5 years to start posting trash like this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900