TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
John Paul hidalgo
NA
9
0
[need help] Filter records within Start and End Date of current year c#
Apr 4 2011 9:52 PM
I'm sorry if i am on the wrong section.
SCENARIO:
i am creating an asp.net page where i use radio buttons for the current year, current month, and week, as well as their previous and next values.
for the current month as well as next month and previous month, my output is just okay. but when i select the year options, i cannot return any values.
by the way, i display the results using GridView.
CODE SAMPLE:
//my query string
if
(
this
.Radiotyear.Checked==
true
||
this
.Radiotweek.Checked ==
true
||
this
.Radiotmonth.Checked ==
true
)
{
queryString =
"SELECT trans.trans_code AS 'Confirmation #', customer.cust_fname AS 'First Name',customer.cust_lname AS 'Last Name', trans.tdate AS 'Schedule Date', trans.ttime AS 'Schedule Time', trans.site_id AS 'Schedule Site' FROM trans INNER JOIN customer ON trans.cust_idno=customer.cust_idno WHERE trans.tdate BETWEEN @searchdatetoday AND @searchdatetodayend "
;
}
System.Data.SqlClient.
SqlCommand
sqlCmd =
new
System.Data.SqlClient.
SqlCommand
(queryString, con);
sqlCmd.Parameters.Add(
"@searchdatetoday"
, System.Data.
SqlDbType
.NVarChar).Value = optionhandler.Text;
sqlCmd.Parameters.Add(
"@searchdatetodayend"
, System.Data.
SqlDbType
.NVarChar).Value = optionhandlerend.Text;
//end of the query string
// the code behind current year radio button
protected void
Radiotyear_CheckedChanged(
object
sender,
EventArgs
e)
{
if
(
this
.Radiotyear.Checked ==
true
)
{
DayOfWeek
day =
DateTime
.Now.DayOfWeek;
int
days = day -
DayOfWeek
.Sunday;
DateTime
start =
DateTime
.Now.AddDays(-days);
DateTime
end = start.AddDays(6);
DateTime
nwstart = end.AddDays(1);
DateTime
nwend = end.AddDays(7);
DateTime
lwend = start.AddDays(-1);
DateTime
lwstart = lwend.AddDays(-6);
DateTime
mstart =
new
DateTime
(.Now.Year, DateTime.Now.Month, 1);
DateTime
mend = mstart.AddMonths(1).AddDays(-1);
DateTime
nmstart = mstart.AddMonths(1);
DateTime
nmend = mstart.AddMonths(2).AddDays(-1);
DateTime
lmstart = mstart.AddMonths(-1);
DateTime
lmend = mstart.AddDays(-1);
DateTime
ystart =
new
DateTime
(
DateTime
.Now.Year, 1, 1);
DateTime
yend = ystart.AddMonths(12).AddDays(-1);
DateTime
nystart = ystart.AddYears(1);
DateTime
nyend = ystart.AddYears(2).AddDays(-1);
DateTime
lystart = ystart.AddYears(-1);
DateTime
lyend = ystart.AddDays(-1);
this
.Radiotoday.Checked =
false
;
this
.Radiotomorrow.Checked =
false
;
this
.Radiotweek.Checked =
false
;
this
.Radionweek.Checked =
false
;
this
.Radiotmonth.Checked =
false
;
this
.Radionmonth.Checked =
false
;
this
.Radiocustom.Checked =
false
;
this
.Radionyear.Checked =
false
;
this
.Radioyesterday.Checked =
false
;
this
.Radiolweek.Checked =
false
;
this
.Radiolmonth.Checked =
false
;
this
.Radiolyear.Checked =
false
;
this
.optionhandler.Text = ystart.ToString(
"d"
);
this
.optionhandlerend.Text = yend.ToString(
"d"
);
}
}
//end of the year radio button code behind
// the code behind current month radio button
protected void
Radiotmonth_CheckedChanged(
object
sender,
EventArgs
e)
{
if (
this
.Radiotmonth.Checked == true)
{
DayOfWeek
day =
DateTime
.Now.DayOfWeek;
int
days = day -
DayOfWeek
.Sunday;
DateTime
start =
DateTime
.Now.AddDays(-days);
DateTime
end = start.AddDays(6);
DateTime
mstart = new
DateTime
(
DateTime
.Now.Year,
DateTime
.Now.Month, 1);
DateTime
mend = mstart.AddMonths(1).AddDays(-1);
this
.Radiotoday.Checked =
false
;
this
.Radiotomorrow.Checked =
false
;
this
.Radiotweek.Checked =
false
;
this
.Radionweek.Checked =
false
;
this
.Radiocustom.Checked =
false
;
this
.Radionmonth.Checked =
false
;
this
.Radiotyear.Checked =
false
;
this
.Radionyear.Checked =
false
;
this
.Radioyesterday.Checked =
false
;
this
.Radiolweek.Checked =
false
;
this
.Radiolmonth.Checked =
false
;
this
.Radiolyear.Checked =
false
;
this
.optionhandler.Text = mstart.ToString(
"d"
);
this
.optionhandlerend.Text = mend.ToString(
"d"
);
}
}
//end of the month radio button code behind
please show me the correct codes here, thanks, and more power
Reply
Answers (
8
)
XML
how to convert pdf to swf file and how to save