missing a directive or namespace

Posted on 2006-06-04
Last Modified: 2013-11-19
I'm using the dataAdapter as you see in the code below.  I'm using VS 2005.  what does the error; The type or namespace name 'SqlDataAdapter' could not be found (are you missing a using directive or an assembly reference?)      mean?

 string strConn = "Database=adventureworks;User ID=se;Password=steve";
            string sqlstr = "select * from production.productcategory";
            using(SqlDataAdapter AWdataadapter = new SqlDataAdapter(strConn,sqlstr));   ****
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
Question by:Steve7423
    LVL 5

    Accepted Solution

    You are missing an using statement:

    using System.Data.SqlClient;

    There is a trick in VS2005, you can just type SqlDataAdapter and you'll see the redbar pops up under the word (assume you already have the dll referenced in the project) hold down ctrl and the period(.) key then enter.  It will add the correct using statement for you.



    Author Comment

    Awsome !!! thanks Aaron.  

    Author Comment

    out of curiosity, how do I add the reference at the top so I don't have to make that reference each time I instantiate a data object like dataadapter?

    LVL 5

    Expert Comment

    Not sure what you mean, you can just type using System.Data.SqlClient on top of your file, so you can use it within the class.  If you have multiple classes that use DataAdaptor you'll need to add it per file.



    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now