c# – 由于SQL字符串而复制值?

前端之家收集整理的这篇文章主要介绍了c# – 由于SQL字符串而复制值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了自己的使用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上的一个Item时,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
原文链接:https://www.f2er.com/csharp/99176.html

猜你在找的C#相关文章