[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

missing a directive or namespace

Posted on 2006-06-04
4
Medium Priority
?
961 Views
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;
            AWdataadapter.Fill(table);
            dbBindSource.DataSource(table);
            dataGridView1.AutoResizeColumn(DataGridViewAutoSizeColumnMode.AllCellsExceptHeader);
            dataGridView1.DataSource(dbBindSource);
0
Comment
Question by:Steve7423
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
aaronfeng earned 400 total points
ID: 16828136
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.

Cheers,

Aaron
http://aaronfeng.blogspot.com
0
 

Author Comment

by:Steve7423
ID: 16828155
Awsome !!! thanks Aaron.  
0
 

Author Comment

by:Steve7423
ID: 16828163
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?

0
 
LVL 5

Expert Comment

by:aaronfeng
ID: 16828177
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.

Cheers,

Aaron
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

872 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