introlux
asked on
Email Composer
Hi,
I would like to know if it can be done and how please. I have a user table with the user details etc. I have created an email composer to send emails out.
I would like to know if it is possible to load up all the values in the database for field email and get them all pasted in the TO text box. I would need to have ',' to seperate each email or it will not work.
Any idea how this can be achieved??
Regards,
introlux
Noe: using SQL Server, C#
I would like to know if it can be done and how please. I have a user table with the user details etc. I have created an email composer to send emails out.
I would like to know if it is possible to load up all the values in the database for field email and get them all pasted in the TO text box. I would need to have ',' to seperate each email or it will not work.
Any idea how this can be achieved??
Regards,
introlux
Noe: using SQL Server, C#
ASKER
I do not understand what this is for:
myCommand.CommandType = CommandType.Text;
As I do not have a text box called CommandType.Text;
myCommand.CommandType = CommandType.Text;
As I do not have a text box called CommandType.Text;
ASKER
Also this code:
foreach datarow in ds.Tables[0].Rows
Does not seem right. I dont even mind loading the emails into the txtbox.Text rather than embedding them in the email.
Whatever way is easier!
Regards,
introlux
foreach datarow in ds.Tables[0].Rows
Does not seem right. I dont even mind loading the emails into the txtbox.Text rather than embedding them in the email.
Whatever way is easier!
Regards,
introlux
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry ^^ my bad I dont have to compiler here:
that should be:
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.Append(datarow["Email"] .ToString( ) + "; ");
}
that should be:
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.Append(datarow["Email"]
}
ASKER
This works perfectly! Only one slight thing. If it cant be sorted, not a problem and will still award the points! The last email displays "," to remove this.
Is this possible???
Regards,
introlux
Is this possible???
Regards,
introlux
You can sort it of course, You can sort it in your SQL statement: Select Email From User ORDER BY Email DESC
or DataTable: I have recommend to use DataSet for the same reason, you can do anything with DataTable, sorting, modifying data:
Create dataView first (for easier reading)
DataView dtv = ds.Tables[0].DefaultView
dtv.Sort = "Email DESC"
foreach(DataRowView drv in dtv.Rows)
But for your case sorting in SQL is better.
To remove the last ; I dont think you need to remove it, if you really want you can replace it or cut it from the string, or put the if statement in that foreach loop
int index = 1;
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.Append(datarow["Email"] .ToString( ) );
if(index != dsTables[0].Rows.Count)
sb.Append("; ");
index += 1
}
Hope this helps
or DataTable: I have recommend to use DataSet for the same reason, you can do anything with DataTable, sorting, modifying data:
Create dataView first (for easier reading)
DataView dtv = ds.Tables[0].DefaultView
dtv.Sort = "Email DESC"
foreach(DataRowView drv in dtv.Rows)
But for your case sorting in SQL is better.
To remove the last ; I dont think you need to remove it, if you really want you can replace it or cut it from the string, or put the if statement in that foreach loop
int index = 1;
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.Append(datarow["Email"]
if(index != dsTables[0].Rows.Count)
sb.Append("; ");
index += 1
}
Hope this helps
ASKER
Compiler Error Message: CS0103: The name 'datarow' does not exist in the current context
Source Error:
Line 113: foreach(DataRow dr in ds.Tables[0].Rows)
Line 114: {
Line 115: sb.Append(datarow["Email"] .ToString( ) );
Line 116: if(index != dsTables[0].Rows.Count)
Line 117: sb.Append("; ");
Source Error:
Line 113: foreach(DataRow dr in ds.Tables[0].Rows)
Line 114: {
Line 115: sb.Append(datarow["Email"]
Line 116: if(index != dsTables[0].Rows.Count)
Line 117: sb.Append("; ");
ASKER
Just used this instead:
txtTo.Text = txtTo.Text.Substring(0, txtTo.Text.Length - 2);
Does the job :-)
txtTo.Text = txtTo.Text.Substring(0, txtTo.Text.Length - 2);
Does the job :-)
ASKER
Thanks! Top Answer!
Hi,
Sorry, syntax error
int index = 1;
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.Append(dr["Email"].ToSt ring() );
if(index != dsTables[0].Rows.Count)
sb.Append("; ");
index += 1
}
Just be aware, this part is only for removing the last ; (Nothing to do with the solution of sorting using DefaultView I mentioned above).
JINN
Sorry, syntax error
int index = 1;
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.Append(dr["Email"].ToSt
if(index != dsTables[0].Rows.Count)
sb.Append("; ");
index += 1
}
Just be aware, this part is only for removing the last ; (Nothing to do with the solution of sorting using DefaultView I mentioned above).
JINN
Glad to help ^^
JINN
JINN
txtTo.Text = txtTo.Text.Substring(0, txtTo.Text.Length - 2);
precisely ^^. that's much better. I forgot the syntax and was too lazy to google for it :D
Good job
JINN
precisely ^^. that's much better. I forgot the syntax and was too lazy to google for it :D
Good job
JINN
What is exactly your problem? Sending email in dot Net or concatenating list of user email?
For emailing problem
https://www.experts-exchange.com/questions/23840055/Good-example-of-email-helper-class-to-send-email.html
For setting up the list of user email:
Make sure you can connect to Users Database
Look at my example
JINN
Open in new window