-
March 31st, 2010, 11:28 AM
#1
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.
-
April 2nd, 2010, 01:41 AM
#2
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.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
-
April 7th, 2010, 02:32 PM
#3
Re: Error converting type object to dataset, but I am not calling or using objects.
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.
-
April 8th, 2010, 03:43 AM
#4
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|