Error converting type object to dataset, but I am not calling or using objects.
I have two sets of code, one to take a varilbe and grab info from SQL DB and fill a DS. The other to assign that DS to a local DS in the calling script. The problem I am getting is
Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'System.Data.DataSet'. An explicit conversion exists (are you missing a cast?)
But it does not make senst to me since I never call anything an object both varibles are delcared as DataSet types.
Code:
public static DataSet GetSQLDataSetByQuery(string SQLQuery)
{
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlConnection Con = GetCon();
using (Con)
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = SQLQuery;
cmd.Connection = Con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds, "TResult");
return ds;
}
}
Code with error:
Code:
DataSet ds = SQLHelper.GetSQLDataSetByQuery(SQLQuery);
DataBind();
As you can see in the code everything is a DataSet so I am not sure where the object is coming from.
Re: Error converting type object to dataset, but I am not calling or using objects.
Isn't here another overloaded GetSQLDataSetByQuery() method? It really looks like everything is OK.
Re: Error converting type object to dataset, but I am not calling or using objects.
Quote:
Originally Posted by
boudino
Isn't here another overloaded GetSQLDataSetByQuery() method? It really looks like everything is OK.
I am sorry I don't understand what you mean.
Re: Error converting type object to dataset, but I am not calling or using objects.
What boudino was suggesting is the possibility of another method called 'GetSQLDataSetByQuery' which did return an object. It is unlikely as the signatures are the same the compiler would have complained about that. Is the code you've posted all in the same assembly or separate ones? Can you also confirm the exact line where the error takes place? Can you also show what the DataBind() method does? I assume it uses the data set? Often times where the compilation error is report may not be the root cause of the error. So it would help to see the bigger picture...