locked
The type or namespace name 'Dataset' could not be found (are you missing a using directive or an assembly reference?) RRS feed

  • Question

  • public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection ("data source=DHRUV-PC\SQLEXPRESS; initial catalog=dcn; integrated security=true;");
                SqlCommand cmd = new SqlCommand ("select * from tbl_city",con);
                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                Dataset ds = new Dataset();
                adpt.Fill(ds);
                city.Items.Add("please select");
                foreach (Datarow dr in ds.Tables[0].Rows)
                {
                    city.Items.Add(dr[1].tostring);
                }

            }
        }

    when i try to compile this code error occurred with dataset.

    platform -  Microsoft visual studio 2010

    database connectivity - Microsoft SQL server 2008.

    Sunday, July 29, 2012 8:26 AM

Answers

  • Do you have this namespase added:

    using System.Data;


    Mitja

    • Marked as answer by Bob Shen Tuesday, August 7, 2012 9:43 AM
    Sunday, July 29, 2012 9:08 AM
  • Remember that C# is case-sensitive. Instead of Dataset, you need to write it as DataSet. Also, be careful with Datarow, which should be DataRow.

    Of course, for this to work you also need a "using System.Data" directive at the beginning of your source code. Please verify that the directive is there, and add it if it is not.

    • Marked as answer by Bob Shen Tuesday, August 7, 2012 9:43 AM
    Sunday, July 29, 2012 9:10 AM

All replies

  • Do you have this namespase added:

    using System.Data;


    Mitja

    • Marked as answer by Bob Shen Tuesday, August 7, 2012 9:43 AM
    Sunday, July 29, 2012 9:08 AM
  • Remember that C# is case-sensitive. Instead of Dataset, you need to write it as DataSet. Also, be careful with Datarow, which should be DataRow.

    Of course, for this to work you also need a "using System.Data" directive at the beginning of your source code. Please verify that the directive is there, and add it if it is not.

    • Marked as answer by Bob Shen Tuesday, August 7, 2012 9:43 AM
    Sunday, July 29, 2012 9:10 AM
  • are you

    "using System.Data;
    using System.Data.SqlClient;" ?

    and make sure your dataBase have 2 columns.

    Sunday, July 29, 2012 9:14 AM