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
Atul Rokade
NA
141
43.6k
How to put datetimepicker control in query in C#
Mar 22 2016 6:37 AM
Hi all,
Iam creating one report in c# where having one combobox which is contain Daily,Weekly
Monthly,HalfYearly,Yearly items if user select in combobox any of them item then in datagridview show respective data as per selection in combobox, as of now its working fine for me but my project manager want dateTime picker option in front end , so if user selected combobox item as weekly and startdate(from datepicker):11/03/2016 and enddate(fromdatetimepicker) as 15/03/2016 so he can get that releted data into datagridview im using access database for this and having only one column Date from using that column only i have to show details i was tried my end but not happening iam putting a code here just tell me how i use datetimepicker option in that
if (comboBox1.SelectedItem.ToString() == "Weekly")
{
string connetionString = null;
connetionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
cnn.ConnectionString = connetionString;
string sql = "SELECT * FROM Billing where Date Between Date() and Date()-6";
OleDbConnection connection = new OleDbConnection(connetionString);
OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Billing");
connection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Billing";
}
else if (comboBox1.SelectedItem.ToString() == "Monthly")
{
string connetionString = null;
connetionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
cnn.ConnectionString = connetionString;
string sql = "SELECT * FROM Billing where Year([Date]) = Year(Now()) And Month([Date]) = Month(Now())";
OleDbConnection connection = new OleDbConnection(connetionString);
OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Billing");
connection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Billing";
}
else if (comboBox1.SelectedItem.ToString() == "HalfYearly")
{
string connetionString = null;
connetionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
cnn.ConnectionString = connetionString;
string sql = "SELECT * FROM Billing where Year([Date]) = Year(Now()) And DatePart('h', [Date]) = DatePart('h', Now())";
OleDbConnection connection = new OleDbConnection(connetionString);
OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Billing");
connection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Billing";
}
else if (comboBox1.SelectedItem.ToString() == "Yearly")
{
string connetionString = null;
connetionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
cnn.ConnectionString = connetionString;
string sql = "SELECT * FROM Billing where Year([Date]) = Year(Date())";
OleDbConnection connection = new OleDbConnection(connetionString);
OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Billing");
connection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Billing";
}
Actually i want only how i will add Start_date(datetimepicker1) and end_date(datetimePicker2) in below query
SELECT * FROM Billing where Date Between Date() and Date()-6 --Weekly
SELECT * FROM Billing where Year([Date]) = Year(Now()) And Month([Date]) = Month(Now()) --monthly
SELECT * FROM Billing where Year([Date]) = Year(Now()) And DatePart('h', [Date]) = DatePart('h', Now()) --"HalfYearly"
SELECT * FROM Billing where Year([Date]) = Year(Date())-- "Yearly"
Reply
Answers (
8
)
Textboxe inside gridview not going to next while press enter
How to create View based on Controller Code in mvc4?