public DataSet GetClgzInfoAll(DateTime fcsj1,DateTime fcsj2,string clbh,string zdzmc)
        {
            try
            {
                ds = sqlhelper.GetDataSet("select xcfymx.fhqdh,fcqk.clbh,xcfymx.xhz,fcqk.fcsj,fcqk.fc_zdzmc,xcfymx.yjddsj,xcfymx.sjdzsj,xcfymx.lksj,xcfymx.ycqk,xcfymx.qrr from xcfymx,fcqk  where xcfymx.fhqdh = fcqk.fhqdh and (fcqk.clbh  like '%"+clbh+"%' and fc_zdzmc like '%"+zdzmc+"%')  and DateDiff(d,'"+ fcsj1 + "',fcsj)>=0 And DateDiff(d,fcsj,'"+ fcsj2 +"')>=0  ");
                return ds;
            }
            catch (Exception)
            {                throw;
            }        }如何将以上语句做成存储过程? 主要是怎么传参?

解决方案 »

  1.   

    select xcfymx.fhqdh,fcqk.clbh,xcfymx.xhz,fcqk.fcsj,fcqk.fc_zdzmc,xcfymx.yjddsj,xcfymx.sjdzsj,xcfymx.lksj,xcfymx.ycqk,xcfymx.qrr from xcfymx,fcqk where xcfymx.fhqdh = fcqk.fhqdh and (fcqk.clbh like '%"+@clbh+"%' and fc_zdzmc like '%"+@zdzmc+"%') and DateDiff(d,'"+ @fcsj1 + "',fcsj)>=0 And DateDiff(d,fcsj,'"+ @fcsj2 +"')>=0 exec 执行
      

  2.   

    MyCmd.CommandType = CommandType.StoredProcedure;
            MyCmd.CommandText = "AddOperation";//存储过程名称
            SqlParameter[] myparam = new SqlParameter[2];
            myparam[0] = new SqlParameter("@KIND", SqlDbType.Int);
            myparam[0].Value = myoperation.EOKind;
            myparam[1] = new SqlParameter("@OPERATORID", SqlDbType.Int);
            myparam[1].Value = myoperation.EOOperatorId;
            foreach (SqlParameter param in myparam)
            {
                MyCmd.Parameters.Add(param);
            }
            MyCmd.ExecuteNonQuery();
    同时觉得楼主字段名取得很不规范 后期开发维护谁看的懂比如fc_zdzmc这个字段什么意思?
      

  3.   

    如何将DAO层的方法做成存储过程????
    我用的是三层架构
    其中sqlhelper.cs类中有个方法GetProcDataSet,他要怎么来接收这么多的参数?
    //查询存储过程
            public DataSet GetProcDataSet(string procName,SqlParameter [] sp)        {
                try
                {
                    conn = Getconn();
                    conn.Open();
                    cmd = new SqlCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = procName;
                    cmd.Connection = conn;
                    foreach(SqlParameter para in sp)
                    {
                        cmd.Parameters.Add(para);
                    }
                    sda = new SqlDataAdapter();
                    sda.SelectCommand = cmd;
                    ds = new DataSet();
                    sda.Fill(ds);
                    return ds;
                }
                catch (Exception)
                {                throw;
                }
                finally
                {
                    conn.Close();
                }
                
            }