存储过程执行 [英] Stored Procudure Execution

查看:136
本文介绍了存储过程执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在执行存储过程时遇到检索数据的问题.

在数据库中执行存储过程时,我可以检索正确的数据.但是当我从网页传递相同的值时,我无法查看相同的数据.

这是我正在使用的代码.

Hi,
I facing problem with retrieving data while executing the Stored Procedure.

When I execute the Stored Procedure in the DataBase, I can able to retrieve the correct data. But when I am passing the same values from the web page I can''t able to view the same data.

This is the code i am using.

//In DBLayer:

 public DataSet InspectionSeach(int cc,string _nameest, string _estadd,string _date_rece)
    {
        SqlConnection conn = OpenConnection();
        DataSet dset = new DataSet();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_InspectionSearch", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@CCnumber", SqlDbType.Int).Value = cc;
            cmd.Parameters.Add("@nameest", SqlDbType.VarChar).Value = _nameest;
            cmd.Parameters.Add("@addest", SqlDbType.VarChar).Value = _estadd;
            cmd.Parameters.Add("@daterec", SqlDbType.VarChar).Value = _date_rece;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
                      da.Fill(dset);
        }
        catch
        {
        }
        conn.Close();
        return dset;       
    }


//In .CS--->

DataSet ds = objDB.InspectionSeach(ccno, txtEstLicNo.Text, txtAddress.Text, txtDate0.Text);

        try
        {
            this.gdvwViolation.DataSource = ds;
            this.gdvwViolation.DataBind();
        }
        catch
        {
        }





Stored Procedure:Alter Procedure[sp_InspectionSearch]
@CCnumber int,
@nameest Varchar (255),
@addest Varchar (255),
@daterec Varchar (50)
AS
if @nameest is not null and len(@nameest)=0 set @nameest=null
select ccno , name_est, add_est,date_rec, Inspection  from tblRequestGen
where  ccno like  isnull(@CCnumber,0) or add_est like  isnull(@addest,0) or name_est like  isnull(@nameest,0) or date_rec like  isnull(@daterec,0)
union all
select ccno , name_est, add_est,date_rec, Inspection  from tblInspReq
where  ccno like  isnull(@CCnumber,0) or add_est like  isnull(@addest,0) or name_est like  isnull(@nameest,0) or date_rec like  isnull(@daterec,0)


请帮助我,非常紧急.
提前致谢. :)


Please help me, its urgent.
Thanks in advance. :)

推荐答案

看起来您使用SQL数据适配器的方式不正确.

Looks like the way you used SQL Data Adaptor is not correct.

dotnet.nag写道:
dotnet.nag wrote:

SqlDataAdapter da =新的SqlDataAdapter(cmd);

SqlDataAdapter da = new SqlDataAdapter(cmd);


相反,请尝试以下操作:


Instead try this:

SqlDataAdapter da = new SqlDataAdapter("sp_InspectionSearch", conn);
SqlCommandBuilder cmdbdr = new SqlCommandBuilder(da);
da.Fill(dset,"MyData");



更新1:很好.从存储过程的数据填充的数据集将具有多个表,这些表的顺序与在存储过程中获取的顺序相同.像... dset.Table [0],dset.Table [1]一样进行检查.



UPDATE 1: Thats fine. The dataset filled from the data of stored procedure will have multiple tables in order as fetched in Stored procedure. Check out like... dset.Table[0], dset.Table[1]..


那么,显而易见,答案是您在网络上做错了什么页.您的参数(如果有)是否正确?您在调用正确的存储过程吗?您如何从网页调用存储的proc?返回什么异常?

您的问题如此含糊,以至于我们根本没有机会为您提供帮助.
Well then, the obvious answer is that you''re doing something wrong in the web page. Are your parameters (if any) correct? Are you calling the correct stored procedure? How are you calling the stored proc from the web page? What exception is being returned?

Your question is so vague that we stand no chance at all in helping you.


另一方面,您有可能从数据库中获得了正确的结果,但您的页面却没有设置为忽略PostBack,(如果是(!IsPostBack)等,等等),所以结果被扔掉了.

无论如何,我会先去那里找问题.
On the other hand, chances are you are getting the correct result back from the database, but your page is not set up to ignore PostBack, ( if (!IsPostBack) etc etc etc), so the result is being tossed out.

Anyway, I''d look there first for the problem.


这篇关于存储过程执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆