C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




date functions....


Posted Date: 02 Sep 2008      Total Responses: 5

Posted By: sujibala       Member Level: Gold     Points: 1





hi friends,

i want solve 2 problems,

first one:i want display date in thes format(02-sep-2008);i used this code(d=dd-MMM-yyyy);but date can't be display

another one:

i want send single message to many emailid;alreay i stored emailid in table

so how to send email to many user

Pl give me friends

Regards
suji






Responses

Author: manoj    02 Sep 2008Member Level: SilverRating:     Points: 2

hai

if u are fetching a date from database
means just u fetch a date in this format
convert(varchar(12),Date(databsefieldname),103) as Date



Author: Appukuttan    02 Sep 2008Member Level: DiamondRating:     Points: 6

If u use format dd-MMM-yyyy defanitly u will get this format(02-sep-2008);

formail :
private void fnSendmail()
{
string Empname = string.Empty;
string Gender = string.Empty;
string sGender = string.Empty;
string EmailId = string.Empty;
try
{
EmployeeEntity objEmp = Database.SelectFrom(EmployeeEntity.Table)
.Where(EmployeeEntity.Table.Id == VetCareSession.LoginID)
.LoadEntity<EmployeeEntity>();
if (objEmp != null)
{
Empname = objEmp.Name;
Gender = objEmp.Gender;
EmailId = objEmp.CorrespondAddress.Email;
}
if (Gender == "Female")
{
sGender = "her";
}
else
{
sGender = "his";
}
//Getting Admin email id's and Higher authority Email id's
string strMailId = fnGetAdminEmployees();
string strccMailid = fnGetHigherAuthority();

MailMessage m_newmail = new MailMessage();
SmtpClient s_client = new SmtpClient();
if (strMailId != "" && strccMailid != "" && EmailId != "")
{
m_newmail.To.Add(strMailId);
m_newmail.CC.Add(strccMailid);

MailAddress fromAdr = new MailAddress(EmailId);
m_newmail.From = fromAdr;
m_newmail.Subject = "About employee's address status ";
m_newmail.Body = Empname + " has been changed " + sGender + " Correspondance / Permanent Address";
m_newmail.IsBodyHtml = true;
s_client.Host = "localhost";
s_client.UseDefaultCredentials = true;
s_client.Send(m_newmail);

ClientScript.RegisterClientScriptBlock(this.GetType(), "Hi!", String.Format("alert('An email has successfully been sent to {0}');", m_newmail.To), true);
m_newmail.Dispose();

}
}
catch (Exception ex)
{
// Response.Write(ex.ToString());
}
}

protected string fnGetAdminEmployees()
{
string Emailid = string.Empty;
List<UserEntity> lstUser = Database.SelectFrom(UserEntity.Table)
.Where(UserEntity.Table.Active == true
&& UserEntity.Table.Role.FullRights == true
&& UserEntity.Table.Role.Active == true)
.LoadList<UserEntity>();
if (lstUser.Count > 0)
{
foreach (UserEntity objUser in lstUser)
{
Emailid += objUser.Employee.CorrespondAddress.Email + ",";
}
if (Emailid != "")
{
Emailid = Emailid.Substring(0, Emailid.Length - 1);
}
}
return Emailid;
}

protected string fnGetHigherAuthority()
{
string Ha_emailid = string.Empty;
EmployeeEntity objEmp = Database.SelectFrom(EmployeeEntity.Table)
.Where(EmployeeEntity.Table.Id == VetCareSession.LoginID)
.LoadEntity<EmployeeEntity>();
if (objEmp != null)
{
Ha_emailid = objEmp.ReportingTo.CorrespondAddress.Email;
}
return Ha_emailid;
}



Author: Karthikeyan S    02 Sep 2008Member Level: GoldRating:     Points: 3

Hi,

1. Whether you used the .ToString() function to format the datetime variable. If so it should work compulsarly else you have did some other mistake.

Syntax for this is:
String lstrDate = ldateLoggedInDate.ToString("dd-MMM-yyyy");

2. Get data from database to a datatable.

a. Get data from database to a datatable:
query for this 'SELECT Email_ID FROM EMAIL_TABLE'
and use the dataadapter and fill the datatable "ldtEmailIDs".

b. use foreach loop and concatenate each email ids.

System.Net.Mail.MailMessage newEmail = new System.Net.Mail.MailMessage();
// or you can use smtp email also ur choice.

foreach(DataRow ldr in ldtEmailIDs.Rows)
{
//newEmail.To.Add("abcd@abcd.com");
newEmail.To.Add(ldr[0].ToString()); // in this way get emailids from //db and add it to "To" object of email object.
}

...
your code follows.



Author: sweety    02 Sep 2008Member Level: GoldRating:     Points: 3

protected void ButtonSubmit_Click(object sender, System.EventArgs e)
{
Server.ScriptTimeout = 1000;
Response.Flush();

SmtpMail.SmtpServer = "localhost";
MailMessage mail = new MailMessage();
mail.To = this.TextBoxTo.Text;
mail.Cc = this.TextBoxCc.Text;
mail.Bcc = this.TextBoxBcc.Text;
mail.From = this.TextBoxFrom.Text;
mail.Subject = this.TextBoxSubject.Text;
mail.Body = this.TextBoxBody.Text;

try
{
SmtpMail.Send(mail);
Response.Write("The Mail has been sent to: ");
Response.Write(mail.To);
Response.Write(mail.Cc);
Response.Write(mail.Bcc);
}
catch(System.Exception ex)
{
Response.Write(ex.Message);
}

Response.Flush();
}

Points of Interest



Author: Sabu C Alex    03 Sep 2008Member Level: GoldRating:     Points: 2

hai

DateTime dt = DateTime.Now;
String dte = dt.ToString("dd-MMM-yyyy");

Hope this will help you
Sabu



Post Reply
You must Sign In to post a response.
Next : No connection could be made because the target machine actively refused it
Previous : preview of pdf file is not coming in PrintPreviewControl
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use