Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

errors in visual studio webpage code (Trying to connect the website to a database)

$
0
0

I am trying to create a website on (visual studio) and connect it to database(Microsoft sql server 2014) first I am learning from a video on youtube the tutorial is about a coffee website and database

I have a few errors but I dont know where is the problem

the errors in this page(Coffee.aspx.cs)

Error    1    Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).    C:\Users\Ziyad 1\Documents\Visual Studio 2013\WebSites\MyWebsite\Pages\Coffee.aspx.cs    7    33    MyWebsite

Error    4    'ASP.pages_coffee_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override    c:\Users\Ziyad 1\AppData\Local\Temp\Temporary ASP.NET Files\root\e78a0b4c\be391a08\App_Web_k4b10ys2.0.cs   572    

Error    3    'ASP.pages_coffee_aspx.GetTypeHashCode()': no suitable method found to override    c:\Users\Ziyad 1\AppData\Local\Temp\Temporary ASP.NET Files\root\e78a0b4c\be391a08\App_Web_k4b10ys2.0.cs   567    

Error    5    'ASP.pages_coffee_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'    c:\Users\Ziyad 1\AppData\Local\Temp\Temporary ASP.NET Files\root\e78a0b4c\be391a08\App_Web_k4b10ys2.0.cs   185    

and here is the page (Coffee.aspx.cs) code

usingSystem;usingSystem.Collections;usingSystem.Text;namespacePages{publicpartialclassPages_Coffee:System.Web.UI.Page{protectedvoidPage_Load(object sender,EventArgs e){FillPage();}privatevoidFillPage(){ArrayList coffeeList =ConnectionClass.GetCoffeeByType(DropDownList1.SelectedValue);StringBuilder sb =newStringBuilder();foreach(Coffee coffee in coffeeList){
                sb.Append(string.Format(@"<table class='coffeeTable'><tr><th rowspan='6' width='150px'><img runat='server' src='{6}' /></th><th width='50px'>Name: </td><td>{0}</td></tr><tr><th>Type: </th><td>{1}</td></tr><tr><th>Price: </th><td>{2} $</td></tr><tr><th>Roast: </th><td>{3}</td></tr><tr><th>Origin: </th><td>{4}</td></tr><tr><td colspan='2'>{5}</td></tr>           </table>", coffee.Name, coffee.Type, coffee.Price, coffee.Roast, coffee.Country, coffee.Review, coffee.Image));
                lblOuput.Text= sb.ToString();}}protectedvoidDropDownList1_SelectedIndexChanged(object sender,EventArgs e){FillPage();}}}

also tis is the page (Coffee.aspx)code

<%@PageTitle=""Language="C#"MasterPageFile="~/Masterpage.master"AutoEventWireup="true"CodeFile="Coffee.aspx.cs"Inherits="Coffee" %><scriptrunat="server">protectedvoidDropDownList1_SelectedIndexChanged(object sender,EventArgs e){}</script><asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><p>
        Select a type:<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"DataSourceID="sds_type"DataTextField="type"DataValueField="type"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><asp:SqlDataSource ID="sds_type" runat="server" ConnectionString="<%$ ConnectionStrings:CoffeeDBConnectionString %>" SelectCommand="SELECT DISTINCT [type] FROM [coffee] ORDER BY [type]"></asp:SqlDataSource></p><p><asp:LabelID="lblOutput"runat="server"Text="Label"></asp:Label></p></asp:Content>

this is th (ConnectionClass.cs)code

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data.SqlClient;publicstaticclassConnectionClass{privatestaticSqlConnection conn;privatestaticSqlCommand command;staticConnectionClass(){string connectionString =ConfigurationManager.ConnectionStrings["coffeeConnection"].ToString();
        conn =newSqlConnection(connectionString);
        command =newSqlCommand("", conn);}publicstaticArrayListGetCoffeeByType(string coffeeType){ArrayList list =newArrayList();string query =string.Format("SELECT * FROM coffee WHERE type LIKE '{0}'", coffeeType);try{
            conn.Open();
            command.CommandText= query;SqlDataReader reader = command.ExecuteReader();while(reader.Read()){int id = reader.GetInt32(0);string name = reader.GetString(1);string type = reader.GetString(2);double price = reader.GetDouble(3);string roast = reader.GetString(4);string country = reader.GetString(5);string image = reader.GetString(6);string review = reader.GetString(7);Coffee coffee =newCoffee(id, name, type, price, roast, country, image, review);
                list.Add(coffee);}}finally{
            conn.Close();}return list;}}

(web.confg)code

<?xml version="1.0"?><configuration><appSettings/><connectionStrings><clear/><addname="coffeeConnection"connectionString="Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=CoffeeDB;Integrated Security=True"providerName="System.Data.SqlClient"/></connectionStrings><system.web><compilationdebug="true"targetFramework="4.0"><assemblies><addassembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><addassembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/><addassembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation><authenticationmode="Windows"/></system.web></configuration>

and finally this is the SQL code

GO
CREATE TABLE [dbo].[coffee]([id][int] IDENTITY(1,1) NOT NULL,[name][varchar](50) NOT NULL,[type][varchar](50) NOT NULL,[price][float] NOT NULL,[roast][varchar](50) NOT NULL,[country][varchar](50) NOT NULL,[image][varchar](255) NULL,[review][text] NOT NULL,
PRIMARY KEY CLUSTERED ([id] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[coffee] ON
INSERT [dbo].[coffee]([id],[name],[type],[price],[roast],[country],[image],[review]) VALUES (1, N'Café au Lait', N'Classic',2.25, N'Medium', N'France', N'../Images/Coffee/Cafe-Au-Lait.jpg', N'A coffee beverage consisting strong or bold coffee (sometimes espresso) mixed with scalded milk in approximately a 1:1 ratio.')
INSERT [dbo].[coffee]([id],[name],[type],[price],[roast],[country],[image],[review]) VALUES (2, N'Caffè Americano', N'Espresso',2.25, N'Medium', N'Italy', N'../Images/coffee/caffe_americano.jpg', N'Similar in strength and taste to American-style brewed coffee, there are subtle differences achieved by pulling a fresh shot of espresso for the beverage base.')
INSERT [dbo].[coffee]([id],[name],[type],[price],[roast],[country],[image],[review]) VALUES (3, N'Peppermint White Chocolate Mocha', N'Espresso',3.25, N'Medium', N'Italy', N'../Images/coffee/white-chocolate-peppermint-mocha.jpg', N'Espresso with white chocolate and peppermint flavored syrups.
Topped with sweetened whipped cream and dark chocolate curls.')
INSERT [dbo].[coffee]([id],[name],[type],[price],[roast],[country],[image],[review]) VALUES (4, N'Irish Coffee', N'Alcoholic',2.25, N'Dark', N'Ireland', N'../Images/coffee/irish coffee.jpg', N'A cocktail consisting of hot coffee, Irish whiskey, and sugar, stirred, and topped with thick cream. The coffee is drunk through the cream.')
SET IDENTITY_INSERT [dbo].[coffee] OFF

I am still a beginner ~~ I need to understand what are these errors and how to solve them



Viewing all articles
Browse latest Browse all 21115

Trending Articles