lixiaogang8571
蓝天候鸟
2015-01-10 13:21

c# 从oracle中查询数据,设置时间参数问题,在线等

  • 参数
  • 查询数据

各位大神,小弟刚接触c#时间不长,写了个程序,从界面上datatimepicker中取出时间,然后在c#代码的sql语句中设置时间参数,无论怎么设置要不就查不到数据,要不就是时间格式设置的不对,下面是代码
public DataTable QueryUsedMaterial(string classgroup, string beginTime, string endTime)
{

        string sql_QueryMaterialsQty = @"select rtrim(mh.schemeid) as 订单,it1.name as 牌号,mh.field3 as 班组,"
            +"ud.modelcode as 盘号名称,ud.callqty as 呼料数量,ud.returnqty as 退还数量,ud.usedqty as 使用数量,"
            +"it.name as 物料名称,ud.USEDMATERIALSDETAILID as ID,ud.usedmaterialsid from machineproductplanhis mh "
            +"inner join usedmaterialshead uh on rtrim(mh.schemeid) = uh.field1 inner join usedmaterialsdetail ud  "
            +"on uh.usedmaterialsid = ud.usedmaterialsid inner join  item it on ud.itemcode = it.code inner join item "
            +"it1 on mh.itemid = it1.itemid where  mh.field3 =:classgroup and mh.createdate >= "
            +"to_date(:beginTime,'yyyy/mm/dd hh24:mi:ss') and mh.createdate <=to_date(:endTime,'yyyy/mm/dd hh24:mi:ss')";
        OracleParameter[] paras = 
    {
        new OracleParameter(":classgroup",OracleType.NVarChar),
        new OracleParameter(":beginTime",OracleType.DateTime),
        new OracleParameter(":endTime",OracleType.DateTime)
    };
        paras[0].Value = classgroup.ToString();
        paras[1].Value = DateTime.Parse(beginTime);
        paras[2].Value = DateTime.Parse(endTime);

        //paras[1].Value = beginTime.ToString();
        //paras[2].Value = endTime.ToString();

        DataTable dt = OracleHelper.SelectDateTable(sql_QueryMaterialsQty, paras);
        return dt;
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答