Link to home
Start Free TrialLog in
Avatar of Tech_Men
Tech_MenFlag for Israel

asked on

i need to compare in the products table and actions table

i need to do this :

in my products table i have for each product unit in stock alarm for exsample

UnitKey    |MinInStock
1000            100
now i have a ActionTable whit all the products Qunataty in the stock
if the Product quantity is less from the MinInStock
i need to get message i have tryd to do this like that :

statusBar1.Text="";
                        listBox1.Items.Clear();

                        sqlConnection1.Close();
                        sqlConnection2.Close();
                  

                        SqlConnection NewConn = new SqlConnection();
                        NewConn.ConnectionString=BizLog.Conn.ConnString();

                        NewConn.Close();

                        IDbCommand cmd1 = this.sqlConnection1.CreateCommand();
                        IDbCommand cmd2 = this.sqlConnection2.CreateCommand();

                        cmd1.CommandText = "SELECT * FROM Products";
                        cmd2.CommandText = "Select * From VIEW1";

                        IDbCommand CmdGetTotalByCode=NewConn.CreateCommand();
                        IDbCommand CmdgetHatByCode = NewConn.CreateCommand();
                  

                        CmdGetTotalByCode.CommandText="SELECT SUM(Kamot) AS ParitTotal FROM Actions WHERE (CodeParit = @CA)";
                        SqlParameter parm = new SqlParameter("@CA",SqlDbType.VarChar,50,"CodeParit");
                        parm.Direction=ParameterDirection.Input;
                        CmdGetTotalByCode.Parameters.Add(parm);

                  
                        CmdgetHatByCode.CommandText="SELECT ProMinimom FROM View1 WHERE (ProKey = @CA)";
                        SqlParameter parm1 = new SqlParameter("@CA",SqlDbType.VarChar,50,"ParitNum");
                        parm1.Direction=ParameterDirection.Input;
                        CmdgetHatByCode.Parameters.Add(parm1);
                  
                        sqlConnection1.Open();
                        sqlConnection2.Open();
                        IDataReader reader = cmd1.ExecuteReader();
                        IDataReader reader1 = cmd2.ExecuteReader();
                        
                        while (reader.Read())
                        {
                              string ProKey = reader["ProKey"].ToString();
                              while(reader1.Read())
                              {
                                    string Pkey=reader1["ProKey"].ToString();
                                    if (ProKey.ToString()==Pkey.ToString())
                                    {
                                          string Degem=reader["ProKey"].ToString();
                              
                                          parm.Value=Degem.ToString();
                                          parm1.Value=Degem.ToString();
                              
                                          NewConn.Open();
                                          int t=Int32.Parse(CmdGetTotalByCode.ExecuteScalar().ToString());
                                          int h=Int32.Parse(CmdgetHatByCode.ExecuteScalar().ToString());
                                          NewConn.Close();
                                          if (h>t)
                                          {
                                                
                                    
                                                listBox1.Items.Add("ProKey" + Degem.ToString() + " " + "U need to order moreי");
                                                
            
                                          }
                                    }
                              }
                        
                        }
                        reader.Close();
                        reader1.Close();

                        sqlConnection1.Close();
                        sqlConnection2.Close();

but its dosent work well
Avatar of Agarici
Agarici
Flag of Romania image

you should make the sql server return only what you need. that is a table that has only products for each you need to make an alert.

you can do this by a simple select like this (i dont know the exact structure of you database so names are more like a guess):

select Products.*
from Products inner join  ActionTable
on Products.ID == ActionTable.ProductID
where Products.MinStock < ActionTable.ProductQuantity

then parse the returned DataTable and do your alert thing


hth,
A.
ASKER CERTIFIED SOLUTION
Avatar of sumix
sumix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial