因此,我正在做一個網站作爲大學項目的一部分在C#Web開發人員,我得到這個錯誤,這是Web服務,它已連接到數據庫我似乎無法找到錯誤:C#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();
}
}
}
你有沒有嘗試縮進你的代碼? –
你有一個多餘的}在你的文件的末尾。去掉它。 –