'Ordertb' 附近的语法不正确
Incorrect syntax near 'Ordertb'
我想刷新和更新 gridview,所以我这样使用 showData():
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'.
您似乎在 Ordertb 之前缺少关键字 'from'。
string qu = string.Format("SELECT * FROM Ordertb", con);
试试这个 SQL 查询:
Select * From Ordertb
在您的代码中:
string qu = string.Format("Select * From Ordertb", con);
我想刷新和更新 gridview,所以我这样使用 showData():
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'.
您似乎在 Ordertb 之前缺少关键字 'from'。
string qu = string.Format("SELECT * FROM Ordertb", con);
试试这个 SQL 查询:
Select * From Ordertb
在您的代码中:
string qu = string.Format("Select * From Ordertb", con);