[英]DataAdapter.Fill(), Error arise as “Incorrect syntax near ')'”
When retrieving a datatable from database using the following code in ASP.Net & C#: The database is located in my local machine. 使用ASP.Net和C#中的以下代码从数据库检索数据表时:数据库位于我的本地计算机中。
string connectionString = @"Data Source=CCS90; Initial Catalog=Ribo; Trusted_Connection=True;";
SqlConnection myConn = new SqlConnection(connectionString);
myConn.Open();
SqlCommand sqlCommand = new SqlCommand("SELECT * FROM PUR_POHEADER WHERE POID = @POID", myConn);
sqlCommand.Parameters.Add("@POID", SqlDbType.Int);
sqlCommand.Parameters["@POID"].Value = Convert.ToInt32(request.ReferenceNo);
DataSet DS = new DataSet();
SqlDataAdapter AD = new SqlDataAdapter(sqlCommand, myConn);
//AD.Fill(DS);
AD.Fill(DS, "POTABLE"); //Error arise at this place
DataTable DT = DS.Tables[0];
myConn.Close();
When compiler comes to the line AD.Fill(DS, "POTABLE");
当编译器到达
AD.Fill(DS, "POTABLE");
行AD.Fill(DS, "POTABLE");
, error occurs at Incorrect syntax near ')
. ,错误发生在
Incorrect syntax near ')
。 What may be the reason? 可能是什么原因?
You may try with 你可以试试
AD.Fill(DS);
instead of 代替
AD.Fill(DS,"PORTABLE");
Also try: 还试试:
SqlDataAdapter AD = new SqlDataAdapter(sqlCommand);
instead of 代替
SqlDataAdapter AD = new SqlDataAdapter(insertStatement, myConn);
You create a SqlCommand
with a SELECT
statement and then you don't use it. 使用
SELECT
语句创建SqlCommand
,然后不使用它。 What is insertStatement
? 什么是
insertStatement
? Surely you should be using sqlCommand
. 当然你应该使用
sqlCommand
。
Problem is here: 问题在这里:
SqlDataAdapter AD = new SqlDataAdapter(insertStatement, myConn);
replace it with: 替换为:
SqlDataAdapter AD = new SqlDataAdapter(sqlCommand);
and also you are using this overload i think: 而且你正在使用这个超载我认为:
AD.Fill(DS, "NameOfDataTable");
then you can access it like this: 然后你可以像这样访问它:
DataTable DT = DS.Tables["NameOfDataTable"];
insetad of using 0 index. 插入使用0索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.