|
Dan O'Riordan wrote: All of the code I am using is placed on this thread.
Clearly not, as you haven't posted any code that would take the email address from the DataSet and put it in the TextBox .
You're going to need to loop through all the rows of the DataSet and join the addresses together with a comma before putting them in the TextBox .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
I did mate:
Calls the Data from the DQL Database:
Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=FigClubs;Integrated Security=True;Pooling=False")
Dim cmd As SqlCommand = New SqlCommand("SELECT Email FROM Members", con)
con.Open()
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataTable As DataTable = New DataTable
myDA.Fill(myDataTable)
con.Close()
con = Nothing
This tells the data to display in the TextBox:
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(My.Settings.ClubEmail, My.Settings.EmailPassword)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(TextBox4.Text)
e_mail.To.Add(EmailTextBox.Text)
e_mail.Subject = TextBox1.Text
e_mail.IsBodyHtml = False
e_mail.Body = TextBox2.Text
Smtp_Server.Send(e_mail)
MsgBox("Your email has been sent.")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
It obviously works because one of the emails in the Database is displayed in the TextBox in question and the email is sent without error to this address.
The TextBox for the To: field is bound to the Datatable called Members. In SQL this data has a field called "Email, where I am getting the email addresses from and displaying them into the TextBox.
Me.MembersTableAdapter.Fill(Me.MembersDataSet.Members)
Can you tell me please how to loop it and separate them with Commas? I have searched everywhere for a solution and not getting anywhere.
Thanks.
|
|
|
|
|
So you're using data-binding to move the data from the DataTable to the TextBox ? That's not going to work; a TextBox will only bind to a single record.
You can either remove the binding and loop through the values in code:
string[] addresses myDataTable.Rows.Cast<DataRow>().Select(row => (string)row[0]).ToArray();
EmailTextBox.Text = string.Join(", ", addresses);
Or you can change the query to return a single row with the concatenated addresses in it, using one of these methods[^]:
SELECT Stuff((SELECT ', ' + Email FROM Members FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 2, '') As Email;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard. I will see if I can implement one of these methods.
Appreciate your help.
Still new to this so it's all a learning curve.
|
|
|
|
|
Dan O'Riordan wrote: So, if you read my first post in this thread, it explains the issue in detail. Sorry, but it doesn't. Nowhere have you shown how you get the email address(es) from the dataset into the textbox, or how you expect to get more than one email address into the text box. It is still not clear whether the database records contain a single email address for each member record or multiple addresses.
If you have a single email address for each member and you want to send the same message to every member, then you should be using a DataReader to extract the detail from your database. You can then read each record in order and add the email address direct to the SMTP message, without the need for a TextBox .
|
|
|
|
|
Sadly, I think he may be using the designer binding crap. That's the only way I can think of where he doesn't have to write any code to get the data into the controls. It's all done for him in the Designer generated code.
|
|
|
|
|
Hi Dave,
You are correct.
It is easier for us who are not geniuses at the coding side of it and rely on forums like this for some help in learning.
|
|
|
|
|
Two problem with the designer generated stuff is two fold:
1) It hides all the details of what's going on and how to do it from you, thereby keeping everything a "secret". It does nothing to teach you how to do this on your own.
2) In order to understand how to make it work and how to fix problems and adapt it to do the weird stuff, like you're doing, you have to understand how it works under the covers! See point 1.
|
|
|
|
|
Exactly the issues so many developers suffer from these days. Three or four clicks on a Wizard and you have a working application, but absolutely no idea how it works.
|
|
|
|
|
Hi again guys,
I am now using the following For Each in my code. I think this is what you are on about regarding looping. Please set me right if I am off path here.
However, if it is right, I am still only getting one address into the mail.to field.
If CheckBox1.Checked = True Then
For Each dr As DataRow In myDataTable.Rows
mailMessage.To.Add(New MailAddress(dr.Item(0).ToString))
Next
Else
mailMessage.To.Add(New MailAddress(EmailTextBox.Text.Trim()))
End If
Thanks in advance.
|
|
|
|
|
I have just tested something similar, although C# rather than VB.NET and it works correctly. You will need to use your debugger to step through the code and discover why the second item does not get added.
|
|
|
|
|
Late but might still help. I am going to assume a few things and then also use code as an example to simplify the possible solution.
Assumptions:
In your DB you probably have a table for Members and another table for EmailMsg (to be distributed to Members)
'Lets assume all Members
Your SQL query will be
"SELECT * FROM DB.Members"
'Lets assume Email based on Subject
Your SQL query will be
"Select * FROM DB.MailMsg WHERE Subject = 'How do I'"
Run the first query against the database to get all the Members and populate your dataset (DBData)
Now populate the "MailTo" textbox:
For i = 0 to DBData.rows - 1
MailTo.AppendText(DBData.rows(i).Item(0) & ";")
Instead of the AppendText option, you can use the "ScrollToCaret" option, but I much prefer the AppendToText option.
To populate the the "Subject" textbox and "EmailMessage" textbox is done exactly the same except you do not need to iterate through the dataset because there should only be one EmailMsg in there. You might want to use the Multiline option in your textbox containing the mail message you wish to distribute.
Good luck and try to stay away from automated Wizards, they really don't teach you anything good.
Regards,
Tino
"Plan your work, Work your plan"
|
|
|
|
|
Hello !
I have a main form . And 2 other forms ( Form2 , Form3).
I want that when Form2 is open should be over the main form.And when form3 is open should be over the Form3 and Main form. ( But the forms should have this behavior only inside the application , so when a other window for example Windows explorer is open , the forms should be behind)
And when the user press the minimize button on main form , all the forms should be minimized on taskbar.
I realize this scenario with Main form and Form2 . Form2 is open with Form2.Show(owner)
But I can't do it with Form3 , because when I click to form2 , the Form3 goes behind.
What can I do ?
Thank you !
|
|
|
|
|
|
Thank you, but I don't want to use Tabcontrol.
There's anything that I can do with forms ?
Thank you !
modified 2-Apr-14 9:59am.
|
|
|
|
|
Who said anything about a "grid control"??
|
|
|
|
|
|
You really don't have to do much at all to get this to work.
Notice that the Form.Show() method has two possibilites? One is no parameter at all:
Dim newForm As New Form2()
newForm.Show()
The override version of this takes an IWin32Window argument. This is the form that owns the new child window and will result in you getting what you want when you minimize your parent form:
Dim newForm As New Form2()
newForm.Show(Me)
|
|
|
|
|
This works with 2 forms , Form1 and Form2.
But doesn't work when I try with form3.
This is the Situation
Form1 is open.
Form2 is open , and has a button that open form3.
If on the button's onclick event :
1) I try : Form3.show(Me) - when I press the minimize button on form 1 , the form 3 is not minimized.( all the form should minimized when I click minimize button on Form1. )
2) I try Form3.show(Form1) - The minimize process is ok , but if I click anywhere on Form2 , the form3 goes behind Form2. I want 3 forms to have this rule : Form2 on top of Form1 , Form3 on top on form1 and form2.( And form3 can be closed before form2 )
What can I do ?
modified 2-Apr-14 12:14pm.
|
|
|
|
|
dilkonika wrote: Form2 on top of Form1 , Form3 on top on form1 and form2 Show them as a dailog, if that is their purpose.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
if a show them as dialog , I can't minimize all the forms when pressing minimize button on Form1.
|
|
|
|
|
That's how it should be; that's how Windows works. You can maximize the app, not each individual window. If they're not a dialog, then they can be focussed.
I'd recommend researching how the default Windows work (and why, and why the user gets frustrated if you change the default behaviour), as opposed to trying to get your custom z-order.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
myForm3.ShowDialog()
or
myForm3.ShowDialog(Me)
Again, read the documentation on the Form class and it's methods.
|
|
|
|
|
if a show them as dialog , I can't minimize all the forms when pressing minimize button on Form1.
|
|
|
|
|
OK, so do you have any clue on how to experiment?? This took me all of about a minute to code:
Form1:
Dim frm As New Form2()
frm.MyTopLevelForm = Me
frm.Show(Me)
Form2:
Public MyTopLevelForm As Form
.
.
.
Dim frm As New Form3()
frm.Show(MyTopLevelForm)
|
|
|
|