[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting Error:  type or namespace name 'OleDbConnection'/'OleDbAdapter' could not be found

Posted on 2004-10-25
8
Medium Priority
?
3,400 Views
Last Modified: 2013-11-19
I am building a Windows App in C# and connecting to an Access database to insert data.  I have:

using System.Data;
using System.Text;
using System.Xml;

private OleDbConnection oleDbConnection;
private OleDbDataAdapter oleDbDataAdapter;

in my app but am getting the following error on the OleDbConnection and OleDbAdapter:

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

I have the following function:

private void addMyRow(string DocType)
{
string doc = DocType.ToString();
string myConnection1 = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=C:\inetpub\wwwroot\DTS\ElectronicData\ElectronicData.mdb");
OleDbConnection myConnect = new OleDbConnection(myConnection1);

OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Imports",myConnect);

da.Fill(ds,"Imports");            
OleDbCommand myOleDbCommand = OleDbCommand.CreateCommand();
           
bool bIsError=false;
  try
  {
    if( data.m_timeStamp.Length == 0)
      MessageBox.Show("An error occurred while importing this record. There is no timestamp.  Please notify Programmer.");
    else
    {
      switch(doc.ToString())
      {
        case "1":
           string sqlcmd = "Insert into Imports (DocumentName, DocumentType)" +
            " values ('" + data.m_DocumentName + "' + '" + data.m_DocumentType + "')";
           myOleDbCommand.CommandText = sqlcmd;
           DataRow myRow = myTable.NewRow();
             myRow("DocumentName") = data.DocumentName;
           myRow("DocumentType") = data.DocumentType;
             myConnection1.Open();
           myTable.Rows.Add(myRow);
           OleDbDataAdapter1.Append(ds, "Imports");
           oleDbCommand1.ExecuteNonQuery();
             break;
        }
     }
  }
  catch(Exception err)
  {
     string str=err.Message;
     bIsError=true;
  }
  finally
  {
    myConnection1.Close();
  }
  if(!bIsError)
  {
    MessageBox.Show("XML Data has been submited!");
  }
  else
  {
     MessageBox.Show("There has been an error with this page.  Please contact the programmer."
  }
}

Any help is appreciated.

ptslv
0
Comment
Question by:ptslv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:rohanbairat3
ID: 12405070
private OleDbConnection oleDbConnection;
private OleDbDataAdapter oleDbDataAdapter;

statements like these should be a part of a class or method.

Declare them inside a class or method and u wont get an error.

-rohan
0
 
LVL 15

Accepted Solution

by:
Timbo87 earned 252 total points
ID: 12405090
Add
using System.Data.OleDb;
0
 
LVL 8

Assisted Solution

by:Razzie_
Razzie_ earned 248 total points
ID: 12405103
you need to add the following using statement:

using System.Data.OleDb;

and it will work.

Cheers,

Razzie
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ptslv
ID: 12405108
They are part of the public class Form1
0
 

Author Comment

by:ptslv
ID: 12405248
I added: using System.Data.OleDb;
 and made some adjustments and corrections, and get the following errors:

1. myConnect.Open(); (string does not contain a definition for Open() )
2.  myConnect.Close(); (string does not contain a definition for Close() )
 3.  OleDbDataAdapter.Append(ds, "Imports"); ( OleDbDataAdapter does not contain a definition for 'Append')  


0
 
LVL 15

Expert Comment

by:Timbo87
ID: 12405464
Replace myConnection1.Open(); with myConnect.Open();
Replace myConnection1.Close(); with myConnect.Close();

I'm not exactly sure what you're trying to do with #3.
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12405538
OleDbDataAdapter does not have an 'Append()' method. Moreover, you use OleDbDataAdapter1 in your code instead of OleDbDataAdapter (notice the extra 1). That can't be right for starters.
0
 

Author Comment

by:ptslv
ID: 12410302
OK.  Let me go back thru my code and clean it up.  Meanwhile, since I received your responses at the about the same time for the original question, I am splitting the points between Timbo87 and Razzie.  If I have anymore problems I will post a new question.  Thanks!

ptslv
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

649 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