i have a form with datetimepicker,button,datagridview. in SQL i have a table with feeid,feeno,classid,feedate,total named fee.
when we click the button, I want to select all the data from sql according to Selected date
(datetimepicker) and it will displayed in datagridview.
Loading

Sam HobbsRank #107 · 20.5K reputationPosted Apr 10, 2011, 10:40 AM EDT
Shyja Abraham66 reputationPosted Apr 10, 2011, 8:32 PM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Apr 10, 2011, 9:15 PM EDT
do coding on DateTimePicker value changed event it has value property private void DateTimePicker1_ValueChanged(Object sender, EventArgs e) { MessageBox.Show("You are in the DateTimePicker.ValueChanged event."); }Shyja Abraham66 reputationPosted Apr 10, 2011, 9:45 PM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Apr 10, 2011, 9:57 PM EDT
and then convert date to string
Shyja Abraham66 reputationPosted Apr 10, 2011, 10:31 PM EDT
Karthikeyan AnbarasanRank #71 · 25.5K reputationPosted Apr 10, 2011, 10:33 PM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Apr 10, 2011, 11:11 PM EDT
so you need to convert your datetime picker value into string and get into strin variable, you can get it easily from net and then do
cmd.CommandText = "select * from fee where feedate='" + DateTime.Parse(variable name) + "'";
DevMaster India41 reputationPosted Apr 10, 2011, 11:43 PM EDT
The problem u are facing is associated with TimeStamp with datetime type of columns, so just remove the time from both side (Database column & variable both) & compare the dates. Whats the issue in this?
The date from front end must be sent in the format you choose in the datetime picker control. (DD/MM or MM/DD)
Example:
SELECT * FROM
WHERE Convert(varchar(20),
Note: The '101' (also 103) can be used to format the datetime fields into 'DD/MM/YYYY' or 'MM/DD/YYYY' formats.
sheetal21 reputationPosted Apr 11, 2011, 1:24 AM EDT
Please check the datatype of your feedate in sql data table. Change it to varchar if it is datetime or smalldatetime.
on button click event u can write
sql command
comm=new sqlcommand("ur query where feedate='"+dtp.value+"' ");
fill the adapter
set datasource property of grid.
Thanks,
Sheetal
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 17, 2013, 2:11 AM EDT
Try this code. It works-
DateTime dt;
SQLConnection con;
SQLCommand cmd;
SQLDataAdapter;
Datatable table;
private void DateTimePicker1_ValueChanged(Object sender, EventArgs e)
{
dt = DateTimePicker1.Selecteddate.value;
}
private void button1_click(object sender, EventArgs e)
{
try
{
con = new SQLConnection(@"connection string");
con.open();
string s = "select * from tablename where Date='"+dt+"'";
cmd = new SQLCommand(con, s);
adp = new SQLDataAdapter();
adp.SelectCommand = cmd;
table = new DataTable();
adp.Fill(table);
datagridview1.dataSource = table;
datagridview1.bind();
}
catch(Exception err){err.Message.ToString();}
finally
{
if(con.State == ConnectionState.open)
{
con.Close();
}
}
}
------------
If you still have issues, and do not mind in sharing the project, do share it.
Hope this helps.