By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,182 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,182 IT Pros & Developers. It's quick & easy.

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

P: 80
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
Share this Question
Share on Google+
2 Replies


P: 80
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

P: 80
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

Post your reply

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