2

だから私はC#Web開発者の大学プロジェクトの一部としてWebサイトを作成していますが、このエラーが発生しています.これはWebサービスであり、データベースに接続されています.エラーを見つけることができないようです:

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

さぁ、ここからどこへ行けばいい?それを削除するとサイト全体が台無しになり、別のブラケットを追加しても役に立ちません。

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();
        }
    }
}
4

1 に答える 1

2

最後の閉じ括弧は、名前空間と一致するもののようです。それを削除する必要があります。

control-kdを使用してコードをフォーマットしてみてください。それが機能する場合は、角かっこ(およびそれらの量)が一致します。

それでもエラーが発生する場合は、コードにさらにエラーが含まれていることを意味します。おそらくusingディレクティブが欠落している可能性がありますが、それは別のエラーです。開き括弧が一致しないため、閉じ括弧を削除する必要があります。

于 2013-01-14T14:04:55.790 に答える