troubleshooting Question

i need to compare in the products table and actions table

Avatar of Tech_Men
Tech_MenFlag for Israel asked on
C#
2 Comments1 Solution208 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
sumix

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros