由于SQL字符串而复制值?

[英]Duplicating values because of SQL string?


I made my own SQL string that uses INNER JOINS. Here is my function:

我创建了自己的使用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 });
}

Now the problem is, when I click one Item on the stocksList ListView the recipeList ListView would have multiple values. Like 5 or so rows of the same values.

现在的问题是,当我点击stocksList ListView上的一个Item时,recipeList ListView将有多个值。像5行左右相同的值。

1 个解决方案

#1


5  

A join with stocksdb is missing. Something like this:

缺少与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 
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/12/21/4ca9e9aab955072413e40ac4ceb852c4.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告