我使用MS Access
作为我的数据库,c#
作为前端。我想从任何月份和年份的特定日期获取数据。我得到的结果只有两位数日期(10,11,12 .....)但不是单位数(01,02,03,.......,09)
这是代码
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();
谢谢
答案 0 :(得分:1)
如果我理解你的问题,你可以这样做:
string sql1 = @"select * from Party_Det where Day(Loandate)=@Loandate order by PName asc ";