2017-08-10 26 views
-1

我想刷新和更新GridView的所以我用showData()這樣的:附近有語法錯誤Ordertb「

protected void ShowData() 
{ 
    con.Open(); 
    string qu = string.Format("SELECT * Ordertb", con); 
    SqlDataAdapter da = new SqlDataAdapter(qu, con); 
    DataSet ds = new DataSet(); 
    da.Fill(ds, "ordertbl"); 
    if (ds.Tables["ordertbl"].Rows.Count > 0) 
    { 
     GridView1.DataSource = ds.Tables[0]; 
     GridView1.DataSourceID = null; 
     GridView1.DataBind(); 
    } 
    con.Close(); 
} 

,但我得到這個錯誤:

Incorrect syntax near 'Ordertb'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'Ordertb'. 
+1

您是否嘗試過運行管理工作室查詢?看起來你錯過了'SELECT * FROM Ordertb' – Captain0

+0

你是對的。謝謝。 – mino

回答

-1

它看起來像你」在Ordertb之前重新找不到關鍵字'from'。

string qu = string.Format("SELECT * FROM Ordertb", con); 
0

試試這個SQL查詢:

Select * From Ordertb 

在您的代碼: