Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my SQL database table column is:
date varchar(50)
while inserting value in date column in below format:
now another form i have two datetimepickeer and a datagridview.1st dtp set by user from date and 2nd to date and datagridview show the record as per above date
i have using below code for do that but is show value only if i entered same date of both dtp , please help ?
da = new SqlDataAdapter("select * from Booking where date between '" + dateTimePicker1.Value.ToString("dd/MMM/yyyy") + "' and '" + dateTimePicker2.Value.ToString("dd/MMM/yyyy") + "'", con);
ds = new DataSet();
da.Fill(ds, "Booking");
dataGridView1.DataSource = ds.Tables[0];

1 solution

Don't save date as string, first change the column to a Date type or DateTime in your database
Then save dtpdate.Value.Date in the database.

when you load data, use parameters and set the parameter values as below

da = new SqlDataAdapter("select * from Booking where date between @date1 and @date2");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900