0

I am using MS Access as my database and c# as front end. I want to fetch data from a specific date of any month and year. I got the result only for two digit dates(10,11,12.....) but not for single digit(01,02,03,.......,09)

Here is the code

string d = dateTimePicker1.Value.Date.ToString("dd");
string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Auto_Finance.accdb;Persist Security Info=False;";
OleDbConnection con = new OleDbConnection(constr);
con.Open();
//string sql1 = @"select * from Party_Det order by PName asc where Loandate like '%'" + d + "'%' order by PName asc ";
//string sql1 = @"select * from Party_Det order by PName asc where Loandate like '*',@Loandate";// order by PName asc ";
//string sql1 = @"select * from Party_Det where Loandate like '*',@Loandate";// order by PName asc ";
string sql1 = @"select * from Party_Det where Day(Loandate)=@Loandate order by PName asc ";
OleDbCommand cmd1 = new OleDbCommand(sql1, con);
cmd1.Parameters.AddWithValue("@Loandate", d);
OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();

Thank You

0

1 Answer 1

1

If I understood your question correctly, you can do this:

string sql1 = @"select * from Party_Det where Day(Loandate)=@Loandate order by PName asc ";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.