|
Hi all
I have created code to display the record on GridView from SQLServer Table.My Question is i want to display record by dayname serial like "Sun","Mon","Tue"..."Sat".
Table Name: "daynanes"
Fields are : dayname varchar(10),menu varchar(10)
Records Look like this:
----------------------
dayName Menu
------ ----
Saturday Idly
Wednesday Dosa
Monday Poori
Thursday Nudles
Friday chapati
Tuesday Idly
Sunday Pongal
i want to dispaly that dayname on Gridview as dayName serial like(Sun ,Mon,...Sat)
This is my code:
----------------
SqlConnection con = new SqlConnection(StrCon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM daynames", con);
DataSet ds = new DataSet();
da.Fill(ds, "Daynames");
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Menu");
dt.Columns.Add("Dayname");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
dr = dt.NewRow();
string str = ds.Tables[0].Rows[i][1].ToString();
if (str == "Monday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr, 0);
}
else if (str == "Tuesday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr, 1);
}
else if (str == "Wednesday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr, 2);
}
else if (str == "Thursday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr,3);
}
else if (str == "Friday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr, 4);
}
else if (str == "Saturday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr, 5);
}
else if (str == "Sunday")
{
dr["Menu"] = ds.Tables[0].Rows[i][0].ToString();
dr["Dayname"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.InsertAt(dr, 6);
}
}
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
|
|
|
|
|
Hi All,
i am getting error while sending mail with attachment file ,and send mail from SMTP server to Gmail ID..
1)Error:
-------
While i use attachment from local machine path i get the error
Invalid mail attachment 'c:\attachFile.txt'
2)Error:
--------
If i try to sent the mail to tamizhms@gmail.com from tamizh@xxxxx.com,
error is
"The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for tamizhms@gmail.com"
My code is :
-----------
MailMessage msg = new MailMessage();
msg.To = txtTo.Text;
msg.From = txtFrom.Text;
msg.Subject = txtSubject.Text;
msg.Body = txtBody.Text;
lblStatus.Text = "Sending.....";
string StrFilePath = "c:\\attachFile.txt";
MailAttachment attach = new MailAttachment(StrFilePath );
msg.Attachments.Add(attach);
SmtpMail.SmtpServer = "mail.xxxxx.com";
SmtpMail.Send(msg);
lblStatus.Text = "Mail sent to ("+txtTo.Text+")";
Please any one of you ,go through my code and solve my problem.
advance Thanks a lot
Regards,
Tamizh
(tamizhms@gmail.com)
|
|
|
|
|
Hi All,
i am getting error while sending mail with attachment file ,and send mail from SMTP server to Gmail ID..
1)Error:
-------
While i use attachment from local machine path i get the error
Invalid mail attachment 'c:\attachFile.txt'
2)Error:
--------
If i try to sent the mail to tamizhms@gmail.com from tamizh@xxxxx.com,
error is
"The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for tamizhms@gmail.com"
My code is :
-----------
MailMessage msg = new MailMessage();
msg.To = txtTo.Text;
msg.From = txtFrom.Text;
msg.Subject = txtSubject.Text;
msg.Body = txtBody.Text;
lblStatus.Text = "Sending.....";
string StrFilePath = "c:\\attachFile.txt";
MailAttachment attach = new MailAttachment(StrFilePath );
msg.Attachments.Add(attach);
SmtpMail.SmtpServer = "mail.xxxxx.com";
SmtpMail.Send(msg);
lblStatus.Text = "Mail sent to ("+txtTo.Text+")";
Please any one of you ,go through my code and solve my problem.
advance Thanks a lot
Regards,
Tamizh
(tamizhms@gmail.com)
modified on Tuesday, April 29, 2008 9:45 AM
|
|
|
|