C# 使用 ADO連結ACCESS
EsnoStr=listMesno[comboBox2.SelectedIndex].ToString();
string StimeStr = DateTime.Now.ToShortDateString()+" 00:00:00";
string sAccessConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Tradjj.mdb";
try{
ADODB.Connection conn = new Connection(sAccessConnection);
conn.Open(sAccessConnection, null, null, -1);
ADODB.Recordset rs0 = new Recordset();
if (DateTime.Now.Hour > PunchOutCheck)
{
textBox1.Text = "YY";
rs0.Open("select * from work_temp "
, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
if (rs0.EOF)
{
rs0.AddNew();
rs0.Fields["wdate"].Value = DateTime.Now.ToShortDateString();
rs0.Fields["DID"].Value = listmemberDID[comboBox2.SelectedIndex].ToString();
rs0.Fields["Esno"].Value = EsnoStr;
rs0.Fields["Stime"].Value = DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString() + ":00";
rs0.Update();
rs0.Close();
textBox1.Text = "1";
}
else
{
rs0.Fields["Etime"].Value = DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString() + ":00";
//rs0.Fields["udate"].Value = DateTime.Now;
rs0.Update();
rs0.Close();
textBox1.Text = "2";
}
}
else {
textBox1.Text = "NN";
StimeStr = DateTime.Now.AddDays(-1).ToShortDateString() + " 00:00:00";
rs0.Open("select * from work_temp where esno='" + EsnoStr + "' and Wdate = '"+ StimeStr + "' and Stime is not null and Etime is null "
, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, (int)ADODB.CommandTypeEnum.adCmdTable);
if (rs0.EOF)
{
textBox1.Text = "3";
rs0.Open("select * from work where esno='" + EsnoStr+ "' and Wdate = '"+ StimeStr + "'"
, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, (int)ADODB.CommandTypeEnum.adCmdTable);
rs0.Fields["Etime"].Value = DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString() + ":00";
rs0.Fields["udate"].Value = DateTime.Now;
rs0.Update();
rs0.Close();
}
else
{
textBox1.Text = "4";
StimeStr =DateTime.Now.ToShortDateString()+ " 00:00:00";
rs0.Open("select * from work_temp where esno='"+ EsnoStr + "' and Wdate = '" + StimeStr + "'"
, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, (int)ADODB.CommandTypeEnum.adCmdTable);
rs0.AddNew();
rs0.Fields["wdate"].Value = DateTime.Now.ToShortDateString();
rs0.Fields["DID"].Value = listmemberDID[comboBox2.SelectedIndex].ToString();
rs0.Fields["Esno"].Value = EsnoStr;
rs0.Fields["Stime"].Value = DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString() + ":00";
rs0.Update();
rs0.Close();
rs0.Update();
rs0.Close();
}
}
}
catch (Exception ex)
{
textBox1.Text = ex.ToString();
}
留言