2

So i am making a website as part of a college project in c# web developer and i am getting this error, this is the web service and it has been connected to the database i cannot seem to find the error:

**Error 1   Type or namespace definition, or end-of-file expected   
Source Error:
Line 278:        }
Line 279:    }
Line 280:}**

Now where can i go from here? Removing it messes up the entire site and adding another bracket does not help.

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Web.Services.Protocols;
using System.Xml.Linq;

    [WebService(Namespace = "http://tempuri.org/")]

public class WebService : System.Web.Services.WebService
    {

    // Connection is initialized 
        OleDbConnection conn;
        OleDbDataReader dbReader;

    private void ConnectToDatabase()
    {
        // Creates a connection to the database
        conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Server.MapPath("App_Data\\Sports Car Auction Database.accdb"));

        // Opens the connection
        conn.Open();
    }

    private void DisconnectDatabase()
    {
        // The connection is closed
        conn.Close();
    }

    [WebMethod]
    public string Login(string userName)
    {
        // Connects to the database
        ConnectToDatabase();

        try
        {
            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = ("Select Password FROM [Buyer Information]  WHERE UserName = '" + userName + "'");

            dbReader = cmd.ExecuteReader();
            dbReader.Read();

            // The result is read from the datareader and returned to the calling method
            string result = (string)dbReader["Password"];
            return result;
        }
        catch (OleDbException)
        {
            // Nothing is returned if there are exceptions
            return null;
        }
    }

     [WebMethod]
    public DataSet ForgetPass(string userName)
    {
        try
        {
            // Connect to database
            ConnectToDatabase();

            // Info from the database is selected via the data adapter
            OleDbDataAdapter adapter = new OleDbDataAdapter(@"SELECT [Secret Question], [Answer] From [Buyer Information] Where [UserName] = '" + userName + "'", conn);

            // Dataset stores results
            DataSet ds = new DataSet();
            adapter.Fill(ds);

            // Dataset is returned to calling method
            return ds;
        }
        catch
        {
            // Nothing is returned if there are exceptions
            return null;
        }
    }

    [WebMethod]
        // Method defines what will be recieved from ChangePassword.aspx
        public void ChangePass(string Pass, string userName)
        {
            // Connects to the database
            ConnectToDatabase();

            // Values in the database are updated
            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = (@"UPDATE [Buyer Information] SET [Password] = '" + Pass + "' WHERE UserName = '" + userName + "'");
            cmd.ExecuteNonQuery();

            // The connection is closed
            DisconnectDatabase();
        }

        [WebMethod]
        // Method define what values will be recieved form register.aspx
        public void RegisterCustomer(string UserName, string Address, string Tel, string Email, string Ques, string Ans, string Pass)
        {
            // Connects to thedatabase
            ConnectToDatabase();

            // Values are inserted into the database
            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = @"INSERT INTO [Buyer Information] ([UserName], [Address], [Telephone], [Email], [Password], [Secret Question], [Answer]) VALUES ('" + UserName + "', '" + Address + "', '" + Tel + "', '" + Email + "', '" + Pass + "', '" + Ques + "', '" + Ans + "')";

            cmd.ExecuteNonQuery();

            // The connection is closed
            DisconnectDatabase();
        }

        [WebMethod]
        public DataSet ViewDetails(string userName)
        {
            try
            {
                // Connects to the database
                ConnectToDatabase();

                // The correct data is selected from the database using the data adapter
                OleDbDataAdapter adapter = new OleDbDataAdapter(@" SELECT Address, Telephone, Email, [Secret Question], Answer FROM [Buyer Information] WHERE UserName = '" + userName + "'", conn);

                // The sesults are stored in the dataset
                DataSet ds = new DataSet();
                adapter.Fill(ds);

                // Dataset is returned to the calling method
                return ds;
            }
            catch (OleDbException)
            {
                // Nothing is returned if there are exceptions
                return null;
            }
        }

        [WebMethod]
        // This defines what values will be recieved from Details.aspx
        public void UpdateCustomer(string userName, string Address, string Tel, string Email, string Ques, string Ans)
        {
            // Connects to the database
            ConnectToDatabase();

            // Updates the database
            OleDbCommand cmd = new OleDbCommand(@"UPDATE [Buyer Information] SET [UserName] = '" + userName + "', [Address] = '" + Address + "', [Telephone] = '" + Tel + "', [Email] = '" + Email + "', [Secret Question] = '" + Ques + "', [Answer] = '" + Ans + "' WHERE [UserName] = '" + userName + "'", conn);

            cmd.ExecuteNonQuery();

            // The connection is closed
            DisconnectDatabase();
        }

        [WebMethod]
        public DataSet SelectItem()
        {
            try
            {
                ConnectToDatabase();

                // Get the model values for the drop down list
                OleDbDataAdapter da = new OleDbDataAdapter("SELECT Model FROM Car", conn);

                DataSet ds = new DataSet();
                da.Fill(ds, "Model");

                return ds;
            }
            catch (OleDbException)
            {
                // Nothing is returned if there are exceptions
                return null;
            }
        }

        [WebMethod]
        public DataSet selectCarInfo(string model)
        {
            try
            {
                // Connects to the database
                ConnectToDatabase();

                // Info is selected from the database via the data adapter
                OleDbDataAdapter adapter = new OleDbDataAdapter(@"SELECT [Car Information].carID, [Car Information].Make, [Car Information].Description, [Car Information].[Starting Bid], [Car Information].[Closing Date] FROM [Car Information] WHERE Model = '" + model + "'", conn);

                // The results are stored in dataset
                DataSet ds = new DataSet();
                adapter.Fill(ds);

                // Dataset is returned to calling method
                return ds;
            }
            catch
            {
                // Nothing is returned if there are exceptions
                return null;
            }
        }

        [WebMethod]
        public decimal highestBidVal(int carID)
        {
            try
            {
                // Connects to the database
                ConnectToDatabase();

                // Selects highestBid to compare to Buyer Informations value
                OleDbCommand cm = conn.CreateCommand();
                cm.CommandText = ("SELECT [Bid Information].HighestBid  FROM [Bid Information] WHERE carID = " + carID + "");

                dbReader = cm.ExecuteReader();
                dbReader.Read();

                decimal highestBidValue = (decimal)dbReader["HighestBid"];
                return highestBidValue;
            }
            catch (OleDbException)
            {
                // Nothing is returned if there are exceptions
                return 0;
            }
        }

        [WebMethod]
        // Method that defines what will be recieved from AddNewItem.aspx
        public void AddNewCar(string Make, string Model, string Description, decimal StartingBid, DateTime closeDate, string owner)
        {
            ConnectToDatabase();

            OleDbCommand cmd = conn.CreateCommand();

            // Values are inserted into the database
            cmd.CommandText = (@" INSERT INTO [Car Information] ([Make], [Model], [Description], [Starting Bid], [Closing Date], [Owner]) VALUES ('" + Make + "', '" + Model + "', '" + Description + "', '" + StartingBid + "', '" + closeDate + "', '" + owner + "')");

            cmd.ExecuteNonQuery();

            // Closes the connection
            DisconnectDatabase();
        }

        [WebMethod]
        // Method that defines what will be recieved from PlaceBid.aspx
        public void AddNewBid(int carid, string userName, decimal bidValue,
            DateTime bidingDate)
        {
            ConnectToDatabase();

            // Values are updated in the database
            OleDbCommand cmd = new OleDbCommand(@"UPDATE [Bid Information] SET [carID] = '" + carid + "', [UserName] = '" + userName + "', [Highest Bid] = '" + bidValue + "', [Bid Date] = '" + bidingDate + "' WHERE [carID] = " + carid + "", conn);

            cmd.ExecuteNonQuery();

            // The connection is closed
            DisconnectDatabase();
        }

        [WebMethod]
        // Method that defines what values will be recieved from Placebid.aspx
        public void AddBid(int carid, string userName, decimal bidValue, DateTime bidingDate)
        {
            ConnectToDatabase();

            OleDbCommand cmd = conn.CreateCommand();
            // Values are inserted into the database
            cmd.CommandText = (@"INSERT INTO [Bid Information] ([carID], [UserName], [UserName], [HighestBid], [Biddate]) VALUES ('" + carid + "', '" + userName + "', '" + bidValue + "', '" + bidingDate + "')");

            cmd.ExecuteNonQuery();

            // Closes the connection
            DisconnectDatabase();
        }
    }
}
2
  • have you tried indenting your code? Commented Jan 14, 2013 at 14:00
  • 2
    You have an excess } at the end of your file. Remove it. Commented Jan 14, 2013 at 14:03

1 Answer 1

2

The last closing bracket seems to be the one which would match the namespace. Removing it should do it.

You can try to format your code with control-k-d. If it works, then your brackets (and the amount of them) match.

If you still get an error, that means your code has more errors in it. You probably are indeed missing a using directive, but that is another error. You do need to remove that closing-bracket, since it has no open-bracket match.

Sign up to request clarification or add additional context in comments.

1 Comment

The formatting code hot key really helped, i then found i had named my web service incorrectly. Works like a charm now. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.