我正在尝试从特定的“deliverySerial”中从我的数据库中检索不同的行。
但是我遇到了一个错误,提示我“声明标量变量 =“@deliverySerial”。
我尝试了许多其他方法,但问题仍然存在。
这是连接:
public class DlDbConn
{
public DlDbConn()
{
}
public SqlConnection GetConnection()
{
SqlConnection dbConn;
dbConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test.mdf;Integrated Security=True;User Instance=True");
return dbConn;
}
}
数据层中的方法:
private String errMsg;
private DlDbConn dbConn;
public testing()
{
dbConn = new DlDbConn();
}
public DataSet Details(String supplierLogo, String supplierName, String supplierAddr, int poNum, String dateSent, int deliverySerial, String deliveryDate,
int quantity, String catSerial, String catName)
{
SqlConnection conn;
StringBuilder sql;
SqlDataAdapter da;
DataSet detail;
conn = dbConn.GetConnection();
detail = new DataSet();
sql = new StringBuilder();
sql.AppendLine("SELECT * FROM (select PO.poNum, PO.dateSent, ViewDelivery.deliverySerial, Supplier.supplierName, Supplier.supplierAddr, Supplier.supplierLogo, ViewDelivery.deliveryDate, Catalog.catSerial, Catalog.catName, PO.quantity, ROW_NUMBER() OVER (PARTITION BY Catalog.catSerial ORDER BY Catalog.catSerial) AS num FROM PO INNER JOIN Supplier ON PO.supplierID = Supplier.supplierID INNER JOIN ViewDelivery ON PO.poNum = ViewDelivery.poNum INNER JOIN Catalog ON PO.catSerial = Catalog.catSerial)AS a WHERE a.num = 1 ");
sql.AppendLine("AND ViewDelivery.deliverySerial = @deliverySerial");
try
{
conn.Open();
da = new SqlDataAdapter(sql.ToString(), conn);
da.SelectCommand.Parameters.AddWithValue("@deliverySerial", deliverySerial);
da.Fill(detail);
}
catch (Exception ex)
{
errMsg = ex.Message;
}
finally
{
conn.Close();
}
return detail;
}