?
Solved

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

Posted on 2004-10-25
8
Medium Priority
?
3,503 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

578 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