Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicating values because of SQL string?

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

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.

like image 450
John Ernest Guadalupe Avatar asked Dec 21 '12 04:12

John Ernest Guadalupe


1 Answers

A join with stocksdb is missing. Something like this:

   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 
like image 55
alexm Avatar answered Sep 19 '22 12:09

alexm