我制作了自己的使用INNER JOINS的SQL字符串。这是我的功能:
string cmdstr = @"SELECT s.*, mdb.menu_name
FROM stocksdb s, recipelist rl
INNER JOIN menudb mdb ON rl.menu_ID = mdb.menu_ID
WHERE rl.stock_ID = '" + stockID + "'";
var cmd = new MySqlCommand(cmdstr, db.mycon);
var dr = cmd.ExecuteReader();
while (dr.Read())
{
var menuname = dr["menu_name"].ToString();
stockIDTxtbox.Text = stockID;
nameTxtBox.Text = dr["stock_name"].ToString();
availableTxtbox.Text = dr["stock_quantity"].ToString();
pricePerPieceTxtbox.Text = dr["stock_pricePerPiece"].ToString();
limitTxtBox.Text = dr["stock_limit"].ToString());
recipeList.Items.Add(new ListViewItem(new[] { menuname });
}
现在的问题是,当我单击
stocksList ListView
上的一个项目时,recipeList ListView
将具有多个值。像5个左右的相同值的行。 最佳答案
缺少与stocksdb的联接。像这样的东西:
SELECT s.*, mdb.menu_name
FROM stocksdb s
INNRER JOIN recipelist rl
ON s.stock_ID= r1.stock_ID <== this join was missing
INNER JOIN menudb mdb
ON rl.menu_ID = mdb.menu_ID
WHERE rl.stock_ID = '" + stockID
关于c# - 是否因为SQL字符串而导致值重复?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13984084/