日期:2014-05-18  浏览次数:20356 次

调用存储过程,返回表,求找错误!!在线等
我的存储过程如下,我想返回查询结果
SQL code

CREATE PROCEDURE [Contrast_Capital_Ordering]
@Basic_Code_Re_Last int,
@Basic_Code_Re int
AS
BEGIN
select * into #A from Ordering_Data where Basic_Code_Re=@Basic_Code_Re_Last ------A表为上次

select *  into #B from Ordering_Data where Basic_Code_Re=@Basic_Code_Re -------B表为本次

select ISNULL(#A.Price_Code,#B.Price_Code) 编码,
ISNULL(#A.Yellow_Num,0) 上次黄,
ISNULL(#B.Green_Num,0)本次绿,
ISNULL(#A.Yellow_Date,null) 上次黄日期,
ISNULL(#B.Green_Date,null) 本次绿日期
from #A full join #B on #A.Price_Code = #B.Price_Code

RETURN
END



调用存储过程的C#代码为如下
C# code

public string Contarst(int Basic_Code_Re_Last, int Basic_Code_Re,  out DataSet result)//对比存储过程
        {
            DataSet ds = new DataSet();
            a.open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Contrast_Capital_Ordering"; //存储过程名
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = a.connstr; 

            SqlParameter[] parameters ={
            new SqlParameter("@Basic_Code_Re_Last",SqlDbType.Int,4),
            new SqlParameter("@Basic_Code_Re",SqlDbType.Int,4),
            };
            parameters[0].Value = Basic_Code_Re_Last;//上次订单号.
            parameters[1].Value = Basic_Code_Re;//本次订单号

            foreach (SqlParameter p in parameters)
            {
                cmd.Parameters.Add(p);
            }    
            SqlDataAdapter rs = new SqlDataAdapter(cmd);
            rs.Fill(ds);
            a.close();
            return ds;
        }



------解决方案--------------------
public string Contarst(int Basic_Code_Re_Last, int Basic_Code_Re, out DataSet result)//对比存储过程
返回string
而你下面又返回return ds;

还有你的 a.open();什么意思
------解决方案--------------------
public string Contarst 改成 public DataSet Contarst
------解决方案--------------------
探讨

引用:

public string Contarst(int Basic_Code_Re_Last, int Basic_Code_Re, out DataSet result)//对比存储过程
返回string
而你下面又返回return ds;

还有你的 a.open();什么意思

a.open()是打开数据库连接
我想返回表……

------解决方案--------------------
先区分是那边出错,存储过程还是代码。
单独将存储过程在查询分析器中执行,看看是否报错
SQL code

exec Contrast_Capital_Ordering  1234,3456

------解决方案--------------------
探讨

弄出来了 汗!!!