problem filling or iterating through table

Results 1 to 2 of 2

Thread: problem filling or iterating through table

  1. #1
    Join Date
    Dec 1969

    Default problem filling or iterating through table

    i have been testing an aspx script to send emails. the script works fine, sending the emails correctly when i specify them one at a time using a web form. the problem comes when i try to send them to a list of recipients pulled from a database.<BR><BR>specifically, my problem is that an table named tblEmailAddresses is either not filling with data correctly in my script or perhaps my script is not effectively iterating through the records. the script is short, so i am enclosing the code as follows. please note that the problem area is with the tblEmailAddresses table:<BR>-----------------------------------------------------------------<BR>&#060;%@ Register TagPrefix="Top" TagName="Table" Src="../toptable.ascx" %&#062;<BR>&#060;%@ Register TagPrefix="Admin" TagName="TOC" Src="AdminTOC.ascx" %&#062;<BR>&#060;% @Import Namespace="System.Data" %&#062;<BR>&#060;% @Import Namespace="System.Data.SqlClient" %&#062;<BR>&#060;% @Import Namespace="System.Web.Mail" %&#062;<BR>&#060;script language="vb" runat="server"&#062;<BR> Sub Page_Load(sender as Object, e as EventArgs)<BR> GetEmailInstructionsForm.Visible = True<BR> DisplayEmailOutputForm.Visible = False<BR> End Sub<BR><BR> Sub Button_Click(sender As Object, e As EventArgs)<BR> Dim sqlString As String = "SELECT UserEmail FROM PracticeCommUsers "<BR> BindData(sqlString)<BR><BR> Dim from As String = FromAddressTextBox.Text<BR> Dim mailto As String <BR> Dim subject As String = SubjectTextBox.Text<BR> Dim body As String = BodyTextBox.Text<BR><BR> Dim myConnection As SqlConnection<BR> Dim objDataset As DataSet<BR> Dim objSQLDataAdapter As SQLDataAdapter<BR> Dim myCommand As SqlCommand<BR> Dim tblEmailAddresses As DataTable<BR><BR> myConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))<BR> myConnection.Open()<BR><BR> objSQLDataAdapter = New SqlDataAdapter()<BR> objDataset = New DataSet()<BR> tblEmailAddresses = New DataTable()<BR><BR> Dim strSQL as String = sqlString<BR><BR> myCommand = New SqlCommand(strSQL, myConnection)<BR> myCommand.CommandType = CommandType.Text<BR><BR> objSQLDataAdapter.SelectCommand = myCommand<BR> objSQLDataAdapter.Fill(objDataset, "tblEmailAddresses")<BR><BR> &#039; iterate through dataset, and send an email to each record in dataset<BR> Dim myRow As DataRow<BR> Dim RowValue As String<BR> For Each myRow In tblEmailAddresses.Rows <BR> RowValue = myRow("UserEmail")<BR> IF RowValue &#060;&#062; "" THEN<BR> mailto = RowValue<BR> SmtpMail.Send(from, mailto, subject, body) <BR> END IF<BR> Next myRow<BR><BR> GetEmailInstructionsForm.Visible = False<BR> DisplayEmailOutputForm.Visible = True<BR> FromAddressLabel.Text = FromAddressTextBox.Text<BR> SubjectLabel.Text = SubjectTextBox.Text<BR> BodyLabel.Text = BodyTextBox.Text<BR> End Sub<BR>&#060;/script&#062;<BR>&#039; the html follows but i wont include it here because it works fine<BR>-----------------------------------------------------------------<BR>can anyone show me what i am doing wrong?<BR><BR>UserEmail is the name of the column in the underlying SQL Server table that my sql string is calling up. i assume that labeled the column the same name in the tblEmailAddresses table. therefore, my problem would wither be in the part of the code that is supposed to fill the table or the adjacent part of the code in which i iterate through the table.<BR><BR>your help is much appreciated. thanks in advance.<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: problem filling or iterating through t

    use stringBuilder or string to store email ids&#039; and concatenating with comma seperated .Once u finish table iteration then SendEmail (ToString ) . This is suitable for u.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts