Error CS0246: The type or namespace name 'DataSet' could not be found (are you missing a using directive or an assembly reference?)

I am using Visual Studio 2010 to work through some intro to webservices materials.  VS and web services are still pretty new to me and I am encoutering an issue with the below code in customerinfo.aspx.  

The code segment that is causing the issue is:

<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        int count;
        string acctype = DropDownList1.SelectedItem.Text;
        getcustomers k = new getcustomers();
        DataSet recs = k.showrecords(acctype);
        GridView1.DataSource = recs.Tables[0].DefaultView;
        GridView1.DataBind();
        count = recs.Tables[0].Row.Count;
        if (count <= 0)
        {
            Label3.Text = "There is no customer with type of account:" +
                acctype;
            GridView1.Visible = false;
        }
        else
        {
            Label3.Text = "Customers with" + acctype + "account type are as follows: ";
            GridView1.Visible = true;
        }
    }    
    </script>

Open in new window


Because of the ‘DataSet’ reference in the code I am hitting an error:  

Error:  The type or namespace name ‘DataSet’ could not be found (are you missing a using directive or an assembly reference?)

It looks like an issue with between the DataSet reference and the customerinfo.aspx.cs file.  If I add ‘using System.Data;’ to the customerinfo.aspx.cs file I still get the error.  If I fully qualify the namespace with System.Data.DataSet, I get passed the DataSet error but get the new error:

'System.Data.DataTable' does not contain a definition for 'Row' and no extension method 'Row' accepting a first argument of type 'System.Data.DataTable' could be found (are you missing a using directive or an assembly reference?)’

What is wrong with the code and what have I missed.


FIle:  customerinfo.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="customerinfo.aspx.cs" Inherits="_Default" %>
<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        int count;
        string acctype = DropDownList1.SelectedItem.Text;
        getcustomers k = new getcustomers();
        DataSet recs = k.showrecords(acctype);
        GridView1.DataSource = recs.Tables[0].DefaultView;
        GridView1.DataBind();
        count = recs.Tables[0].Row.Count;
        if (count <= 0)
        {
            Label3.Text = "There is no customer with type of account:" +
                acctype;
            GridView1.Visible = false;
        }
        else
        {
            Label3.Text = "Customers with" + acctype + "account type are as follows: ";
            GridView1.Visible = true;
        }
    }    
    </script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<strong><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="left: 238px; position: relative; top: 206px" Text="Submit" /></strong>
        <asp:Label ID="Label1" runat="server" Style="position: relative; font-family: Garamond; font-size: large; font-weight: 700; text-align: left;" Text="XYZ Bank Information"></asp:Label>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:banking %>" SelectCommand="SELECT DISTINCT [type_of_account] FROM [master]"></asp:SqlDataSource>
        <asp:Label ID="Label3" runat="server" Style="left: -120px; position: relative; top: 44px" Text="Label 3" Visible="False"></asp:Label>
        <asp:Label ID="Label2" runat="server" Style="left: -240px; position: relative; top: 88px" Text="Select type of accounts"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server" Style="left: -220px; position: relative; top: 88px" DataSourceID="SqlDataSource1" DataTextField="type_of_account"> </asp:DropDownList>
        <asp:GridView ID="GridView1" runat="server" Style="left: 397px; position: relative; top: 88px"></asp:GridView>

    </div>
    </form>
</body>
</html>

Open in new window





FIle:  customerinfo.aspx.cs
using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Open in new window




JBHaire2004Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

appariCommented:
try changing after fully qualifying the namespace with System.Data.DataSet,

count = recs.Tables[0].Row.Count;

to

count = recs.Tables[0].Rows.Count;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hi JBHaire2004,

(1) Since you are using server side code in .aspx page you would need to import namespace as

<%@ Import Namespace="System.Data" %>

to solve error Error CS0246: The type or  namespace name 'DataSet' could not be found (are you missing a using  directive or an assembly reference?)

(2) Change your code count = recs.Tables[0].Row.Count; as

recs.Tables[0].Rows.Count; (you forget to put 's')

Let us know if you have any more problem?

Regards,
VSS

cubaman_24Commented:
Hello:
Avoid using in-line code. Use aspx files and separate code behind.
This line in your aspx file should make your day:

<%@ Import Namespace="System.Data" %>

Best regards.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hello @cubaman_24

I have already mentioned the solution (import namespace) suggested by you.

Regards,
VSS
cubaman_24Commented:
Hello vs00saini:
Yes, you gave the right answer before than me, if our answer works points should go for you.
Best regards.
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hello @cubaman_24

Points to both of us as you have also suggested Avoid using in-line code. Use aspx files and separate code behind.

Happy Answering Expert!

Regards,
VSS
JBHaire2004Author Commented:
I greatly appreciate all answers and all assistance with this.  I selected the first answer as it was the solutions that I attempted and it corrected the issue.  Also the first solution was the solution that pointed out I missed an “S” and to correct this suggested change “count = recs.Tables[0].Row.Count;    to   count = recs.Tables[0].Rows.Count;”.   Although the other answer elaborated differently on the missing “s” the core underlying suggestion was the same in all 3 posts. I did not assess points to for the suggestion <%@ Import Namespace="System.Data" %> as it was not part of what I used to get my code to successfully compile.  I instead went the path of “fully qualifying the namespace with System.Data.DataSet”.  I am not familiar with the code snippet <%@ Import Namespace="System.Data" %> or its usage.  I was uncertain of where to place it.  Was it top replace the top line <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="customerinfo.aspx.cs" Inherits="_Default" %>?  As I wasn’t certain as to placement I did not use it.  Last I did not assess points to the “Avoid using in-line code. Use aspx files and separate code behind.”; because in my limited and novice understanding and the way I interpreted things , I had already attempted to use separate code behind by adding ”using System.Data;” to the customerinfo.aspx.cs and still encountered the issue.

 I hope that explanation is satisfactory to all involved parties and that I certainly did not intend to offend anyone.  I pay to participate in this forum as I greatly value the input of all the experts here and would never intentionally conduct myself in a manner that would offend or alienate any of the experts that were so kind as to assist me in working through, what to me, are complicated issues or areas I which I am not as seasoned.

Thanks!
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hi JBHaire2004,

It's ok that you solved your problem with the help of suggestion of appari. The issue was the question in your heading; so I answered according to that. That's why I was thinking for splitting of points.

Because if someone encounters the question in PAQ and if he/she try to get solution to that ; then at that point solution would be as I mentioned. Suppose you are creating some big web application so how many time you would write fully qualified name. At that point the best solution would be to use same <%@ Import Namespace="Fully qualified Namespace Here" %>

As you said you were not certain about its placement, you should ask clarification from us again so that you can reach to best permanent working solution (as other developers recommends). It would be placed after <%@ Page Language="C#" AutoEventWireup="true"   CodeFile="customerinfo.aspx.cs" Inherits="_Default" %>

Happy Coding :)

Regards,
VSS
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.