Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i am using three tier architecture for search the data and bind to gridview, My code is

DAL:
C#
public DataSet DSet(string Stxt)
   {
       try
       {
           con = new SqlConnection(connect);
           con.Open();
           cmd = new SqlCommand("Search_sp", con);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@searchparameter", Stxt);
           da = new SqlDataAdapter(cmd);
           ds = new DataSet();
           da.Fill(ds);
           return ds;
       }
       catch
       {
           throw;
       }
       finally
       {
           con.Close();
       }
   }

BAL:

C#
public int txtsrch(string txtsrch)
    {
        try
        {
            return cfdal.DSet(txtsrch);
        }
        catch
        {
            throw;
        }
        finally
        {
            cfdal = null;
        }
    }


aspx page code:

ASP
protected void Button2_Click(object sender, EventArgs e)
   {
       //connection();
       //query = "Search_sp";
       //cmd = new SqlCommand(query, con);
       //cmd.CommandType = CommandType.StoredProcedure;
       //cmd.Parameters.AddWithValue("@searchparameter", txtsearch.Text).ToString();
       //search_grid.DataSource = cmd.ExecuteReader();
       //search_grid.DataBind();

       string stxt = txtsearch.Text;
       search_grid.DataSource = cfbal.txtsrch(stxt);
       search_grid.DataBind();
   }


Here my Problem is it showing Error(can't convert dataset to int) but i don't know how to do it, even though i refer in google still i didn't get proper output,
Thanks for your advice ....
Posted
Updated 8-May-14 6:36am
v2
Comments
[no name] 8-May-14 12:35pm    
Well Captain Obvious says that you are trying to return a DataSet from a method that is coded to return an integer.
prasanna.raj 8-May-14 12:39pm    
ya in BAL part... how can i clear that...
[no name] 8-May-14 12:44pm    
Why don't you try changing the method signature to return a DataSet?

1 solution

The function DSet returns a dataset...
C#
public DataSet DSet(string Stxt)
so when you use it here
C#
public int txtsrch(string txtsrch)
    {
        try
        {
            return cfdal.DSet(txtsrch);
        }

you are getting the error because you want txtsrch to return an int
Given that you later use
search_grid.DataSource = cfbal.txtsrch(stxt);
I'm guessing you really don't want to return an int from txtsrch!

Try
C#
public DataSet txtsrch(string txtsrch)
instead
 
Share this answer
 
Comments
prasanna.raj 8-May-14 12:49pm    
NO still it showing Error !
prasanna.raj 8-May-14 12:51pm    
could u tell me any other suggestion...
CHill60 8-May-14 12:53pm    
What error now?
prasanna.raj 8-May-14 12:55pm    
same error in BAL(can't implicitly convert dataset to int)
CHill60 8-May-14 12:56pm    
And you changed the function to be public DataSet txtsrch(string txtsrch) ?? That's the only place you showed us where you had used int

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