我现在遇到问题,我需要完成目前正在为学生进行职业培训的系统。我想使用oledbdatareader根据当月的数据在我的excel上获得该月的数据,并将其放在标签上
示例:
我有2018年8月18日至2018年12月18日,我需要获取2018年10月18日的记录。
这是我的代码
string path = Server.MapPath("login.xlsx");
String conString = "provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;ReadOnly=True;HDR=Yes;\"";
using (OleDbConnection con = new OleDbConnection(conString))
{
OleDbCommand com = new OleDbCommand("select [Sheet2$].[EMPLOYEE_NO],[Sheet2$].[EMPLOYEE_NAME],[Sheet2$].[HIRED_DATE],[Sheet2$].[REGULIZED_DATE],[Sheet2$].[POSITION]," +
"[Sheet3$].[EMPLOYEE_NO],[Sheet3$].[DATE],[Sheet3$].[REM_BALANCE]," +
"[Sheet4$].[EMPLOYEE_NO],[Sheet4$].[DATE],[Sheet4$].[REM_BALANCE]" +
" from ([Sheet2$] INNER JOIN [Sheet3$] ON [Sheet2$].[EMPLOYEE_NO]=[Sheet3$].[EMPLOYEE_NO] )" +
"INNER JOIN [Sheet4$] ON [Sheet3$].[EMPLOYEE_NO]=[Sheet4$].[EMPLOYEE_NO] where [Sheet2$].[EMPLOYEE_NO]=" + session + "", con);
con.Open();
OleDbDataReader read = com.ExecuteReader();
while (read.Read())
{
Label8.Text = read["EMPLOYEE_NAME"].ToString();
Label9.Text = read["POSITION"].ToString();
Label10.Text = string.Format("{0:dd/MM/yyyy}", read["HIRED_DATE"]);
Label11.Text = string.Format("{0:dd/MM/yyyy}", read["REGULIZED_DATE"]);
Label12.Text = Convert.ToDateTime(read["Sheet3$.DATE"]).ToString("dd/MM/yyyy");
Label13.Text = read["Sheet3$.REM_BALANCE"].ToString();
}