我正在使用下面的代码从我的表中获取结果并将其绑定到 gridview 控件。但我收到以下错误:
"System.Data.SqlClient.SqlException: Incorrect syntax near 'x'" at "sqlda.Fill(ds1)"
.
我是 ASP.NET 的新手,无法编写好的查询。
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "WITH x AS (SELECT *, rn = ROW_NUMBER() OVER (PARTITION BY PersonRFID ORDER BY DateStamp) FROM AISDb where action = 'IN'), y As(SELECT *, rna = ROW_NUMBER() OVER (PARTITION BY PersonRFID ORDER BY DateStamp)FROM AISDb where action='OUT') SELECT y.ID,x.ID,x.PersonName,y.PersonName,x.PersonRFID, DtATEDIFF(MINUTE, x.TimeStamp, y.TimeStamp) FROM x ,y where x.PersonRFID = y.PersonRFIDAnd x.rn=y.rnaAND cast(x.Datestamp as date) = cast(y.Datestamp as date)Order By x.PersonName";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds1 = new DataSet();
sqlda.Fill(ds1);