ASP.NET Access Database C# codebehind the page compile error | Member | | Join Date: Dec 2006
Posts: 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: - 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 - 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.
| | Member | | Join Date: Dec 2006
Posts: 80
| | | re: ASP.NET Access Database C# codebehind the page compile error
ASP.NET html code: - <%@ Page Language="c#" AutoEventWireup="false" Codebehind="DataGridDisplay.aspx.cs" Inherits="Chapter7.DataGridDisplay" %>
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
<HTML>
-
<HEAD>
-
<title></title>
-
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
-
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
-
<meta name="vs_defaultClientScript" content="JavaScript">
-
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
-
</HEAD>
-
<body MS_POSITIONING="GridLayout">
-
<form id="Form1" method="post" runat="server">
-
<asp:DataGrid id="MyDG" style="Z-INDEX: 101; LEFT: 30px; POSITION: absolute; TOP: 107px" runat="server" DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
-
</asp:DataGrid>
-
<asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 143px; POSITION: absolute; TOP: 54px" runat="server"
-
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">
-
</form>
-
</body>
-
</HTML>
-
| | Member | | Join Date: Dec 2006
Posts: 80
| | | re: ASP.NET Access Database C# codebehind the page compile error
C# code behind the page: - using System;
-
using System.Collections;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Web;
-
using System.Web.SessionState;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.HtmlControls;
-
-
namespace Chapter7
-
{
-
/// <summary>
-
/// Summary description for DataGridDisplay.
-
/// </summary>
-
public class DataGridDisplay : System.Web.UI.Page
-
{
-
protected System.Web.UI.WebControls.DataGrid MyDG;
-
protected System.Web.UI.WebControls.Label Label1;
-
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
-
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
-
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
-
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
-
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
-
protected Chapter7.MyDS myDS1;
-
protected System.Data.DataView dataView1;
-
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
-
-
private void Page_Load(object sender, System.EventArgs e)
-
{
-
OleDbDataAdapter1.Fill(myDS1);
-
Page.DataBind();
-
// Put user code to initialize the page here
-
}
-
-
#region Web Form Designer generated code
-
override protected void OnInit(EventArgs e)
-
{
-
//
-
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
-
//
-
InitializeComponent();
-
base.OnInit(e);
-
}
-
-
/// <summary>
-
/// Required method for Designer support - do not modify
-
/// the contents of this method with the code editor.
-
/// </summary>
-
private void InitializeComponent()
-
{
-
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
-
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
-
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
-
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
-
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
-
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
-
this.myDS1 = new Chapter7.MyDS();
-
this.dataView1 = new System.Data.DataView();
-
((System.ComponentModel.ISupportInitialize)(this.myDS1)).BeginInit();
-
((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
-
//
-
// oleDbDataAdapter1
-
//
-
this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
-
this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
-
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
-
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
-
new System.Data.Common.DataTableMapping("Table", "Products", new System.Data.Common.DataColumnMapping[] {
-
new System.Data.Common.DataColumnMapping("ModelName", "ModelName"),
-
new System.Data.Common.DataColumnMapping("ProductID", "ProductID"),
-
new System.Data.Common.DataColumnMapping("UnitCost", "UnitCost")})});
-
this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
-
//
-
// oleDbDeleteCommand1
-
//
-
this.oleDbDeleteCommand1.CommandText = "DELETE FROM Products WHERE (ProductID = ?) AND (ModelName = ? OR ? IS NULL AND Mo" +
-
"delName IS NULL) AND (UnitCost = ?)";
-
this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
-
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));
-
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));
-
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));
-
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));
-
//
-
// oleDbConnection1
-
//
-
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";
-
//
-
// oleDbInsertCommand1
-
//
-
this.oleDbInsertCommand1.CommandText = "INSERT INTO Products(ModelName, ProductID, UnitCost) VALUES (?, ?, ?)";
-
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
-
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ModelName", System.Data.OleDb.OleDbType.VarWChar, 50, "ModelName"));
-
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ProductID", System.Data.OleDb.OleDbType.Integer, 0, "ProductID"));
-
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("UnitCost", System.Data.OleDb.OleDbType.Currency, 0, "UnitCost"));
-
//
-
// oleDbSelectCommand1
-
//
-
this.oleDbSelectCommand1.CommandText = "SELECT ModelName, ProductID, UnitCost FROM Products WHERE (SubCategoryID = 2)";
-
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
-
//
-
// oleDbUpdateCommand1
-
//
-
this.oleDbUpdateCommand1.CommandText = "UPDATE Products SET ModelName = ?, ProductID = ?, UnitCost = ? WHERE (ProductID =" +
-
" ?) AND (ModelName = ? OR ? IS NULL AND ModelName IS NULL) AND (UnitCost = ?)";
-
this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
-
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ModelName", System.Data.OleDb.OleDbType.VarWChar, 50, "ModelName"));
-
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ProductID", System.Data.OleDb.OleDbType.Integer, 0, "ProductID"));
-
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("UnitCost", System.Data.OleDb.OleDbType.Currency, 0, "UnitCost"));
-
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));
-
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));
-
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));
-
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));
-
//
-
// myDS1
-
//
-
this.myDS1.DataSetName = "myDS";
-
this.myDS1.Locale = new System.Globalization.CultureInfo("en-US");
-
this.Load += new System.EventHandler(this.Page_Load);
-
((System.ComponentModel.ISupportInitialize)(this.myDS1)).EndInit();
-
((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
-
-
}
-
#endregion
-
-
-
}
-
}
-
|  | Similar .NET Framework bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,537 network members.
|