CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    36

    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.

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  3. #3
    Join Date
    Feb 2010
    Posts
    36

    Re: Error converting type object to dataset, but I am not calling or using objects.

    Quote Originally Posted by boudino View Post
    Isn't here another overloaded GetSQLDataSetByQuery() method? It really looks like everything is OK.
    I am sorry I don't understand what you mean.

  4. #4
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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
  •  





Click Here to Expand Forum to Full Width

Featured