Click here to Skip to main content
16,016,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
//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
        {
        }


SQL
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. :)
Posted
Updated 17-May-10 6:35am
v4
Comments
Sandeep Mewara 17-May-10 11:59am    
you need to post the code that is retrieving data for you... there must be some mistake.

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

dotnet.nag wrote:
SqlDataAdapter da = new SqlDataAdapter(cmd);

Instead try this:
SQL
SqlDataAdapter da = new SqlDataAdapter("sp_InspectionSearch", conn);
SqlCommandBuilder cmdbdr = new SqlCommandBuilder(da);
da.Fill(dset,"MyData");


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]..
 
Share this answer
 
v2
Comments
ureachnag 17-May-10 13:57pm    
Thanks for your reply Sandeep.
I have written a Stored Procedure to retrieve data from 2 tables, in this sitation how i have to fill adapter.
Please hlep me.
Thanks,
Nag
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.
 
Share this answer
 
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.
 
Share this answer
 
Nag,

Specify the size for the varchar, use -
C#
cmd.Parameters.Add("@nameest", SqlDbType.VarChar,255).Value = _nameest;


not -
C#
cmd.Parameters.Add("@nameest", SqlDbType.VarChar).Value = _nameest;


because the VarChar takes a default size (i thinks its 10), and when the value you pass exeeds the default size the parameter value will be truncated and sent to SP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900