谢谢你的回答,不过我还有一个事情搞不懂.加入表名是book,要查询的字段是"ysrq",我这样写为什么报错 OleDbConnection objConnection; string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:/test.mdb"; objConnection = new OleDbConnection(strConnection); ds = new DataSet();
objConnection.Open();
sda=new OleDbDataAdapter("select max(ysrq) from book where tsbh='" + tsbh.Text + "' and ysc='" + ysc.Text + "'", objConnection); sda.Fill(ds, "book"); DateTime old = (DateTime)ds.Tables["book"].Rows(0)["ysrq"]; 在最后一个行Rows那里提示错误,说什么cannot be used like a method
sda=new OleDbDataAdapter("select max(ysrq) as ysrq from book where tsbh='" + tsbh.Text + "' and ysc='" + ysc.Text + "'", objConnection);
已解决,代码如下: DataSet ds; OleDbConnection objConnection; string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:/test.mdb"; objConnection = new OleDbConnection(strConnection); ds = new DataSet();
objConnection.Open();
sda=new OleDbDataAdapter("select max(ysrq) as ysrq from book where tsbh='" + tsbh.Text + "' and ysc='" + ysc.Text + "'", objConnection); sda.Fill(ds, "book"); DateTime old = Convert.ToDateTime( ds.Tables["book"].Rows[0]["ysrq"]); DateTime now = Convert.ToDateTime(jtrq.Text); TimeSpan span = now.Subtract(old); int days = span.Days;
得到datatime 印刷日期dt1
用datatime.now获取当期日期dt2
然后用
TimeSpan span = dt2.Subtract(dt1);
int dayDiff(相差天数) = span.Days;
然后再用if判断dayDiff 就可以了
思路就是这样了 你自己具体情况具体分析下就可以了
OleDbConnection objConnection;
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:/test.mdb";
objConnection = new OleDbConnection(strConnection);
ds = new DataSet();
objConnection.Open();
sda=new OleDbDataAdapter("select max(ysrq) from book where tsbh='" + tsbh.Text + "' and ysc='" + ysc.Text + "'", objConnection); sda.Fill(ds, "book");
DateTime old = (DateTime)ds.Tables["book"].Rows(0)["ysrq"]; 在最后一个行Rows那里提示错误,说什么cannot be used like a method
DataSet ds;
OleDbConnection objConnection;
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:/test.mdb";
objConnection = new OleDbConnection(strConnection);
ds = new DataSet();
objConnection.Open();
sda=new OleDbDataAdapter("select max(ysrq) as ysrq from book where tsbh='" + tsbh.Text + "' and ysc='" + ysc.Text + "'", objConnection); sda.Fill(ds, "book");
DateTime old = Convert.ToDateTime( ds.Tables["book"].Rows[0]["ysrq"]);
DateTime now = Convert.ToDateTime(jtrq.Text);
TimeSpan span = now.Subtract(old);
int days = span.Days;