473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ASP.NET Access Database C# codebehind the page compile error

Hi, I am working on a class assignment, and I am receiving an error, that has me stumped. In the assignment I am trying to bind a datagrid control to an Access Database. When I compile the Web Application I get the following error:

Expand|Select|Wrap|Line Numbers
  1. c:\inetpub\wwwroot\Chapter7\DataGridDisplay.aspx.cs(32): The type or namespace name 'OleDbDataAdapter1' could not be found (are you missing a using directive or an assembly reference?)
I have the OleDbDataAdapter declared
Expand|Select|Wrap|Line Numbers
  1. protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
So does anyone have any idea what could be causing the compiler to kick out this error? Is there a piece of code that I must be missing somewhere?

I am going to include the Code Behind the page code and the asp.net html code in two posts immediately following this one. Any help that could be provided would be greatly appreciated.
Feb 23 '07 #1
2 1873
ASP.NET html code:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="c#" AutoEventWireup="false" Codebehind="DataGridDisplay.aspx.cs" Inherits="Chapter7.DataGridDisplay" %>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  3. <HTML>
  4.     <HEAD>
  5.         <title></title>
  6.         <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
  7.         <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
  8.         <meta name="vs_defaultClientScript" content="JavaScript">
  9.         <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  10.     </HEAD>
  11.     <body MS_POSITIONING="GridLayout">
  12.         <form id="Form1" method="post" runat="server">
  13.             <asp:DataGrid id="MyDG" style="Z-INDEX: 101; LEFT: 30px; POSITION: absolute; TOP: 107px" runat="server" DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
  14.             </asp:DataGrid>
  15.             <asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 143px; POSITION: absolute; TOP: 54px" runat="server"
  16.                 ForeColor="DarkSlateGray" Font-Size="Medium" Font-Names="Trebuchet MS"> Binding an Access Database to a DataGrid Control</asp:Label><IMG style="Z-INDEX: 103; LEFT: 6px; POSITION: absolute; TOP: 3px" src="images/header2.jpg">
  17.         </form>
  18.     </body>
  19. </HTML>
  20.  
Feb 23 '07 #2
C# code behind the page:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. namespace Chapter7
  13. {
  14.     /// <summary>
  15.     /// Summary description for DataGridDisplay.
  16.     /// </summary>
  17.     public class DataGridDisplay : System.Web.UI.Page
  18.     {
  19.         protected System.Web.UI.WebControls.DataGrid MyDG;
  20.         protected System.Web.UI.WebControls.Label Label1;
  21.         protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
  22.         protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
  23.         protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
  24.         protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
  25.         protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
  26.         protected Chapter7.MyDS myDS1;
  27.         protected System.Data.DataView dataView1;
  28.         protected System.Data.OleDb.OleDbConnection oleDbConnection1;
  29.  
  30.         private void Page_Load(object sender, System.EventArgs e)
  31.         {
  32.             OleDbDataAdapter1.Fill(myDS1);
  33.             Page.DataBind();
  34.             // Put user code to initialize the page here
  35.         }
  36.  
  37.         #region Web Form Designer generated code
  38.         override protected void OnInit(EventArgs e)
  39.         {
  40.             //
  41.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  42.             //
  43.             InitializeComponent();
  44.             base.OnInit(e);
  45.         }
  46.  
  47.         /// <summary>
  48.         /// Required method for Designer support - do not modify
  49.         /// the contents of this method with the code editor.
  50.         /// </summary>
  51.         private void InitializeComponent()
  52.         {    
  53.             this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
  54.             this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
  55.             this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
  56.             this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
  57.             this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
  58.             this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
  59.             this.myDS1 = new Chapter7.MyDS();
  60.             this.dataView1 = new System.Data.DataView();
  61.             ((System.ComponentModel.ISupportInitialize)(this.myDS1)).BeginInit();
  62.             ((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
  63.             // 
  64.             // oleDbDataAdapter1
  65.             // 
  66.             this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
  67.             this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
  68.             this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
  69.             this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  70.                                                                                                         new System.Data.Common.DataTableMapping("Table", "Products", new System.Data.Common.DataColumnMapping[] {
  71.                                                                                                                                                                                                                     new System.Data.Common.DataColumnMapping("ModelName", "ModelName"),
  72.                                                                                                                                                                                                                     new System.Data.Common.DataColumnMapping("ProductID", "ProductID"),
  73.                                                                                                                                                                                                                     new System.Data.Common.DataColumnMapping("UnitCost", "UnitCost")})});
  74.             this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
  75.             // 
  76.             // oleDbDeleteCommand1
  77.             // 
  78.             this.oleDbDeleteCommand1.CommandText = "DELETE FROM Products WHERE (ProductID = ?) AND (ModelName = ? OR ? IS NULL AND Mo" +
  79.                 "delName IS NULL) AND (UnitCost = ?)";
  80.             this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
  81.             this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ProductID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
  82.             this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ModelName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ModelName", System.Data.DataRowVersion.Original, null));
  83.             this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ModelName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ModelName", System.Data.DataRowVersion.Original, null));
  84.             this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_UnitCost", System.Data.OleDb.OleDbType.Currency, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitCost", System.Data.DataRowVersion.Original, null));
  85.             // 
  86.             // oleDbConnection1
  87.             // 
  88.             this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\Inetpub\wwwroot\Chapter7\data\TaraStore.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False";
  89.             // 
  90.             // oleDbInsertCommand1
  91.             // 
  92.             this.oleDbInsertCommand1.CommandText = "INSERT INTO Products(ModelName, ProductID, UnitCost) VALUES (?, ?, ?)";
  93.             this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
  94.             this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ModelName", System.Data.OleDb.OleDbType.VarWChar, 50, "ModelName"));
  95.             this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ProductID", System.Data.OleDb.OleDbType.Integer, 0, "ProductID"));
  96.             this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("UnitCost", System.Data.OleDb.OleDbType.Currency, 0, "UnitCost"));
  97.             // 
  98.             // oleDbSelectCommand1
  99.             // 
  100.             this.oleDbSelectCommand1.CommandText = "SELECT ModelName, ProductID, UnitCost FROM Products WHERE (SubCategoryID = 2)";
  101.             this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
  102.             // 
  103.             // oleDbUpdateCommand1
  104.             // 
  105.             this.oleDbUpdateCommand1.CommandText = "UPDATE Products SET ModelName = ?, ProductID = ?, UnitCost = ? WHERE (ProductID =" +
  106.                 " ?) AND (ModelName = ? OR ? IS NULL AND ModelName IS NULL) AND (UnitCost = ?)";
  107.             this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
  108.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ModelName", System.Data.OleDb.OleDbType.VarWChar, 50, "ModelName"));
  109.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ProductID", System.Data.OleDb.OleDbType.Integer, 0, "ProductID"));
  110.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("UnitCost", System.Data.OleDb.OleDbType.Currency, 0, "UnitCost"));
  111.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ProductID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
  112.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ModelName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ModelName", System.Data.DataRowVersion.Original, null));
  113.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ModelName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ModelName", System.Data.DataRowVersion.Original, null));
  114.             this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_UnitCost", System.Data.OleDb.OleDbType.Currency, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitCost", System.Data.DataRowVersion.Original, null));
  115.             // 
  116.             // myDS1
  117.             // 
  118.             this.myDS1.DataSetName = "myDS";
  119.             this.myDS1.Locale = new System.Globalization.CultureInfo("en-US");
  120.             this.Load += new System.EventHandler(this.Page_Load);
  121.             ((System.ComponentModel.ISupportInitialize)(this.myDS1)).EndInit();
  122.             ((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
  123.  
  124.         }
  125.         #endregion
  126.  
  127.  
  128.     }
  129. }
  130.  
Feb 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
1
by: ani | last post by:
When I try to open the web form page, I get a designer error which says: 'the file could not be loaded into the web forms designer. Please correct the following error and then try loading it...
6
by: Nehal Shah | last post by:
I've read that in the Page Directive of an aspx page, changing the CodeBehind attribute to Src saves you from having to compile the page before refreshing. This is preferable in a large...
12
by: A.M | last post by:
Hi, Using VS.NET 2003, If i use SRC page attribute instead of CodeBehind, do i still have intelisence and generally IDE support for that? Thanks, Ali
12
by: Wardeaux | last post by:
All, Wanting to find a way to create web pages to add to my website without having to recompile the codebehind everytime I want to add a new one... Here's the deal: I have a web app that takes...
7
by: Jack | last post by:
Hello, What is the difference between SRC and CODEBEHIND Tags? Example <%@ Page Language="vb" ValidateRequest="false" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" %> or
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
6
by: Plamen Doykov | last post by:
Hi all I have converted a simple project from ASP.NET 1 to 2.0 with the latest prerelease of Visual Studio 2005. The problem is I can't access internal members from the code behind. It gives:...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.