点击按钮,从数据库发送多条短信 [英] sending multiple SMS from database on button click
问题描述
我正在学校管理系统,我想向他们的父母发送多条学生表现的短信。我已经在SQL服务器上存储了父母电话号码。我想根据父母电话检索学生表现,但是我的系统不是如果发送带有空白数据的第一条短信正在工作。下面是使用的代码。
进口系统
Imports System.Data
Imports System.ComponentModel
Imports System.Text
Imports System.Collections.Generic
< span class =code-keyword> Imports GsmComm.GsmCommunication
Imports GsmComm.PduConverter
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic
公开 类 sendS1results
Dim pdu As SmsSubmitPdu
Dim phone,grade,mesg < span class =code-keyword> As 新 ArrayList
Dim a 作为 整数
私人 < span class =code-keyword> Sub sendS1results_Load( ByVal sender As 对象, ByVal e As System.EventArgs)把手温泉n> 我 .Load
致电 loadCbmTerm()
< span class =code-keyword>结束 Sub
公共 Sub loadCbmTerm()
使用 cbmTerm
.Items.Add( 1)
.Items.Add( 2)
.Items.Add( 3)
结束 使用
结束 Sub
私人 Sub btnSend_Click( ByVal sender 作为系统。对象, ByVal e As System.EventArgs)句柄 btnSend.Click
调用 send()
结束 Sub
公开 Sub send()
Dim con As 新 SqlConnection(conString)
Dim com As 新 SqlCommand
Dim dr As SqlDataReader
Dim dat As 新 DataTable
con.Open()
使用 com
.Connection = con
.CommandType = CommandType.Text
.CommandText = select * from vS1Phones
dr = com.ExecuteReader
结束 使用
while dr.Read
phone.Add(dr.Item( 0 ))
End while
con.Close()
对于 每个 n 在手机中
txtPhone.Text = n
如果 con.State = ConnectionState.Closed 那么
con。 Open()
Else
使用 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
结束 使用
while dr.Read
mesg.Add(dr.It em( 0 )+ dr.Item( 1 ))
结束
对于 每个 m 在中mesg
txtMessage.AppendText(m)
下一步
结束 如果
mesg.Clear()
< span class =code-comment> txtMessage.Clear()
尝试
pdu = 新 SmsSubmitPdu(txtMessage.Text,txtPhone.Text)
ModemSettings.ms.Open()
ModemSettings.ms.SendMessage(pdu )
ModemSettings.ms.Close()
Catch ex As 例外
MessageBox.Show( 发送短信时出错)
结束 尝试
' txtMessage.Clear()
下一步 n
con.Close()
' phone.Clear()
结束 Sub
问题出在这里:
如果 con.State = ConnectionState.Closed 然后
con.Open()
Else
使用 com
...
结束 如果
您要做的第一件事就是检查连接是否已关闭,确实如此。然后你必须打开它。mesg
变量永远不会被数据填充。
一个简单的断点和调试将帮助你。
我建议你按照这个链接[ ^ ]并尝试/实现不同的东西。
dfgdfgdf
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.
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
The problem is here:
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. Themesg
variable is never filled with data.
A simple breakpoint and debug will help you.
I suggest you follow this Link [^] and try/implement something different.
dfgdfgdf
这篇关于点击按钮,从数据库发送多条短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!