Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi m getting this type of error..cannot implicity converty type..can any one suggest me how to solve this.??
public DataSet GetTender1(int ID)
        {
            TenderTypeDAL tenderDAL = new TenderTypeDAL();
            DataSet dataTable = new DataSet();
//this linve m getting error...
            dataTable = tenderDAL.GetTender1(ID);

            return dataTable;
        }

thanks
Posted
Updated 26-Mar-12 23:06pm
v2
Comments
senguptaamlan 27-Mar-12 4:57am    
tenderDAL.GetTender1(ID) what this method returns?
ythisbug 27-Mar-12 4:58am    
public DataTable GetTender1(int ID)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(varConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_GetTenderByID";

cmd.Parameters.Add(new SqlParameter("@Id", ID));
SqlDataAdapter adapter = new SqlDataAdapter(cmd);

try
{
adapter.Fill(dt);
}
catch
{
dt = null;
}
return dt;
}
senguptaamlan 27-Mar-12 5:02am    
So the above method returns a DataTable...and Ur assigning this DataTable to a DataSet type reference.....is that possible??? Its quite expected that Ur getting error. Change Ur code....and go through the code I'm mentioning in the answer part.
Muralikrishna8811 27-Mar-12 5:02am    
Hi

its better to write

dataTable.Tables.Add(tenderDAL.GetTender1(ID));
ythisbug 27-Mar-12 6:27am    
thanks bro..i tried this working now.

It depends on what tenderDAL.GetTender1 returns: If it is an object which is a DataSet then it is no problem: just cast it, preferably with a check in there:
C#
dataTable = (DataSet) tenderDAL.GetTender1(ID);

or
C#
dataTable = tenderDAL.GetTender1(ID) as DataSet;
if (dataTable != null)
   {
   ...
   }

If it doesn't, then you need to look at what it does return, and see if there is a good cast between them.
 
Share this answer
 
Comments
ythisbug 27-Mar-12 5:05am    
no its not working..thanks
C#
public DataSet GetTender1(int ID)
{
            DataSet dt = new DataSet();
            SqlConnection con = new SqlConnection(varConnectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_GetTenderByID";

            cmd.Parameters.Add(new SqlParameter("@Id", ID));
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            try
            {
                adapter.Fill(dt);
            }
            catch
            {
                dt = null;
            }
            return dt;
}


now call the following method

C#
public DataSet GetTender1(int ID)
{
            TenderTypeDAL tenderDAL = new TenderTypeDAL();
            DataSet ds= new DataSet();
            ds= tenderDAL.GetTender1(ID);
 
            return ds;
}


please, mark this as answer if it resolves the error...
 
Share this answer
 
Comments
ythisbug 27-Mar-12 5:10am    
but also same error..thanks.
senguptaamlan 27-Mar-12 5:14am    
have you changed both the methods??? I've run the code and not getting any error..please go through the code thoroughly.
ythisbug 27-Mar-12 6:26am    
ya ..i tried other way its working..
senguptaamlan 27-Mar-12 8:04am    
hi if my approach has solved your problem please mark it as answer.
XML
Hello

Please define dataset and datatable this way

<pre lang="c#">
 private DataSet GetDataSet()
    {
        DataSet companydata = new DataSet("CompanyList");

        DataTable company = companydata.Tables.Add("company");

        company.Columns.Add("Id", typeof(Guid));


</pre>
 
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