我正在尝试将查询作为DataSource
传递给我的水晶报告。但是,不是显示过滤数据的报告,而是显示关联表中的所有数据。
这就是我正在做的传递数据
访问器
class cStockIssuanceSlipDetails
{
public string itemCode { get; set; }
public string itemDescription { get; set; }
public double unitcost { get; set; }
public int quantity { get; set; }
public double amount { get; set; }
}
过滤
public DataSet Products_info(int slip_no)
{
string queryProducts = "SELECT p.ItemCode,p.itemDescription,p.SaleCost,slip.Quantity,slip.Amount FROM tblstockissuanceslip slip " +
"INNER JOIN tblprowareinventory pi ON slip.inventoryID_FK = pi.inventoryID " +
"INNER JOIN tblprowareproducts p ON pi.ItemID_FK = p.ItemID "+
"WHERE slip.SIP_NO = ?slipno";
using (MySqlCommand cmd = new MySqlCommand(queryProducts,con.connection))
{
cmd.Parameters.AddWithValue("?slipno", slip_no);
DataSet ds = new DataSet();
using (MySqlDataAdapter mda = new MySqlDataAdapter(cmd))
{
mda.Fill(ds);
return ds;
}
}
}
设置DataSource
List<cStockIssuanceSlipDetails> _List = new List<cStockIssuanceSlipDetails>();
DataSet ds = Data.Products_info(5);
foreach (DataRow dr in ds.Tables[0].Rows)
{
_List.Add(new cStockIssuanceSlipDetails
{
itemCode = dr["itemCode"].ToString(),
itemDescription = dr["itemDescription"].ToString(),
unitcost = Convert.ToDouble(dr["SaleCost"]),
quantity = Convert.ToInt32(dr["Quantity"]),
amount = Convert.ToDouble(dr["Amount"]),
});
}
rStockIssuanceSlip1.SetDataSource(_List);
答案 0 :(得分:0)
你能尝试这样的事吗?
class cStockIssuanceSlipDetails
{
public string itemCode { get; set; }
public string itemDescription { get; set; }
public double unitcost { get; set; }
public int quantity { get; set; }
public double amount { get; set; }
--Create a variable to store the value you want to pass in your sql statement
--use this variable to store the value before concatenating in to your sql statement
public string topass { get; set; }
}
Filter
public DataSet Products_info(int slip_no)
{
string queryProducts = "SELECT p.ItemCode,p.itemDescription,p.SaleCost,slip.Quantity,slip.Amount FROM tblstockissuanceslip slip " +
"INNER JOIN tblprowareinventory pi ON slip.inventoryID_FK = pi.inventoryID " +
"INNER JOIN tblprowareproducts p ON pi.ItemID_FK = p.ItemID "+
"WHERE slip.SIP_NO = ""+topass+";
using (MySqlCommand cmd = new MySqlCommand(queryProducts,con.connection))
{
--remove line below
cmd.Parameters.AddWithValue("?slipno", slip_no);
--remove line above
DataSet ds = new DataSet();
using (MySqlDataAdapter mda = new MySqlDataAdapter(cmd))
{
mda.Fill(ds);
return ds;
}
}
}
实际发生的是,参数无法检索您尝试传递的值。只是一个提示,尝试学习如何在SQL中使用存储过程和函数,它们将使您的生活更加和平。