I am having problems with errors in my connection class file while is breaking the rest of my website. the error message i get when i try to preview my tours.aspx page:
Compiler Error Message: CS1001: Identifier expected Line19
here is the code for my connection class file.
using System.Collections; using System.Configuration; using System.Data.SqlClient; using Entities; public static class ConnectionClass { private static SqlConnection conn; private static SqlCommand command; static ConnectionClass() { string connectionString = ConfigurationManager.ConnectionStrings["toursConnection"].ToString(); conn = new SqlConnection(connectionString); command = new SqlCommand("", conn); } #region tours public static tours GettoursByID(int) { string query = string.Format("SELECT * FROM tours WHERE id = '{0}'", id); tours tours = null; try { conn.Open(); command.CommandText = query; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { string name = reader.GetString(1); string date = reader.GetString(2); double price = reader.GetDouble(3); string venue = reader.GetString(4); string country = reader.GetString(5); string image = reader.GetString(6); string description = reader.GetString(7); tours = new tours(id, name, date, price, venue, country, image, description); } } finally { conn.Close(); } return tours; } public static ArrayList GettoursByType(string toursType) { ArrayList list = new ArrayList(); string query = string.Format("SELECT * FROM tours WHERE type LIKE '{0}'", toursType); 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); tours tours = new tours(id, name, type, price, roast, country, image, review); list.Add(tours); } } finally { conn.Close(); } return list; } public static void Addtours(tours tours) { string query = string.Format( @"INSERT INTO tours VALUES ('{0}', '{1}', @prices, '{2}', '{3}','{4}', '{5}')", tours.Name, tours.date, tours.venue, tours.Country, tours.Image, tours.description); command.CommandText = query; command.Parameters.Add(new SqlParameter("@prices", tours.Price)); try { conn.Open(); command.ExecuteNonQuery(); } finally { conn.Close(); command.Parameters.Clear(); } } #endregion #region Users public static User LoginUser(string name, string password) { //Check if user exists string query = string.Format("SELECT COUNT(*) FROM toursDB.dbo.users WHERE name = '{0}'", name); command.CommandText = query; try { conn.Open(); int amountOfUsers = (int)command.ExecuteScalar(); if (amountOfUsers == 1) { //User exists, check if the passwords match query = string.Format("SELECT password FROM users WHERE name = '{0}'", name); command.CommandText = query; string dbPassword = command.ExecuteScalar().ToString(); if (dbPassword == password) { //Passwords match. Login and password data are known to us. //Retrieve further user data from the database query = string.Format("SELECT email, user_type FROM users WHERE name = '{0}'", name); command.CommandText = query; SqlDataReader reader = command.ExecuteReader(); User user = null; while (reader.Read()) { string email = reader.GetString(0); string type = reader.GetString(1); user = new User(name, password, email, type); } return user; } else { //Passwords do not match return null; } } else { //User does not exist return null; } } finally { conn.Close(); } } public static string RegisterUser(User user) { //Check if user exists string query = string.Format("SELECT COUNT(*) FROM users WHERE name = '{0}'", user.Name); command.CommandText = query; try { conn.Open(); int amountOfUsers = (int)command.ExecuteScalar(); if (amountOfUsers < 1) { //User does not exist, create a new user query = string.Format("INSERT INTO users VALUES ('{0}', '{1}', '{2}', '{3}')", user.Name, user.Password, user.Email, user.Type); command.CommandText = query; command.ExecuteNonQuery(); return "User registered!"; } else { //User exists return "A user with this name already exists"; } } finally { conn.Close(); } } #endregion #region Orders public static void AddOrder(ArrayList orders) { try { command.CommandText = @"INSERT INTO orders VALUES (@client, @productName, @amount, @price, @date, @orderSent)"; conn.Open(); foreach (Order order in orders) { command.Parameters.Add(new SqlParameter("@client", order.Client)); command.Parameters.Add(new SqlParameter("@productName", order.ProductName)); command.Parameters.Add(new SqlParameter("@amount", order.Amount)); command.Parameters.Add(new SqlParameter("@price", order.Price)); command.Parameters.Add(new SqlParameter("@date", order.Date)); command.Parameters.Add(new SqlParameter("@orderSent", order.OrderSent)); command.ExecuteNonQuery(); command.Parameters.Clear(); } } finally { conn.Close(); } } #endregion } <?xml version="1.0" encoding="utf-8"?> <!-- --> this is my web confif file <
?xml version="1.0" encoding="utf-8"?> <!-- --> <configuration> <appSettings /> <connectionStrings> <clear /> <add name="toursConnection" connectionString="Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=CoffeeDB;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="CoffeeDBConnectionString" connectionString="Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=CoffeeDB;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <!-- --> <compilation debug="true" targetFramework="4.0"> <assemblies> <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> </assemblies> </compilation> <!-- --> <authentication mode="Windows" /> <!-- </customErrors> --> <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"> <controls> <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" /> </controls> </pages> </system.web> <!-- --> </configuration> tours.aspx.cs code below
using System; using System.Collections; using System.Text; using Entities; namespace Pages { public partial class Pages_tours : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { FillPage(); } private void FillPage() { ArrayList toursList = ConnectionClass.GettoursByType(!IsPostBack ? "%" : DropDownList1.SelectedValue); StringBuilder sb = new StringBuilder(); foreach (tours tours in toursList) { sb.Append( string.Format( @"<table class='toursTable'> <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>", tours.Name, tours.Type, tours.Price, tours.Roast, tours.Country, tours.Review, tours.Image)); } lblOuput.Text = sb.ToString(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { FillPage(); } } }