我在C#下面的代碼來檢索表中的列:爲什麼有試圖從SQL表中選擇時錯誤
protected void Page_Load(object sender, EventArgs e)
{
using (OleDbConnection connection = new OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;" +
"Data Source=wmg-erp-db;Initial Catalog=DP;User ID=zh;Password=zhas"))
{
OleDbDataAdapter adapter = new OleDbDataAdapter("SHAPE {SELECT FROM [DP].[dbo].[BT]} ", connection);
DataSet customers = new DataSet();
adapter.Fill(customers, "Customers");
}
}
我收到以下錯誤:
Exception Details: System.Data.OleDb.OleDbException: Incorrect syntax near the keyword 'FROM'.
Source Error:
Line 35:
Line 36: DataSet customers = new DataSet();
Line 37: adapter.Fill(customers, "Customers");
Line 38: }
Line 39: }
Source File: c:\Webserver\WEXEC\Booking\booking.aspx.cs Line: 37
Stack Trace:
[OleDbException (0x80040e14): Incorrect syntax near the keyword 'FROM'.]
System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr) +60
System.Data.OleDb.OleDbDataReader.NextResult() +630
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +546
System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +264
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +9
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +325
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +420
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +280
booking.Page_Load(Object sender, EventArgs e) in c:\Webserver\EXEC\Booking\booking.aspx.cs:37
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
如何我可以解決這個問題嗎?
你忘了你的'SELECT'部分後指定列。像'SHAPE * {SELECT FROM [DP]。[dbo]。[BT]}' –
DUH !!!我完全忽略了那一個。謝謝。 – SearchForKnowledge