Solved

how can i know if the command affect row in the db ?

Posted on 2006-11-26
2
189 Views
Last Modified: 2011-08-18
hi there
i have this func :

private bool CalcMem(int Month,int Kamot,string FamCode,string Sph,string Cyl)
            {
                  Memoza = (Kamot / 12) * Month;
                  MessageBox.Show(Memoza.ToString());
            MyCon.ConnectionString=BizLog.Conn.ConnString();

                  try
                  {
                        IDbCommand cmdUpdate = MyCon.CreateCommand();
                        cmdUpdate.CommandText="update Products set MelayMinmum=@MinSum "+
                              "where ParitFamilyId=@Fam and ParitSPH=@Sph and ParitCYL=@Cyl";

                        SqlParameter parm = new SqlParameter("@MinSum",SqlDbType.Int,8);
                        parm.Direction=ParameterDirection.Input;
                        parm.Value=Memoza;

                        SqlParameter parm1 = new SqlParameter("@Fam",SqlDbType.VarChar,50);
                        parm1.Direction=ParameterDirection.Input;
                        parm1.Value=FamCode;

                        SqlParameter parm2 = new SqlParameter("@Sph",SqlDbType.VarChar,50);
                        parm2.Direction=ParameterDirection.Input;
                        parm2.Value=Sph;

                        SqlParameter parm3 = new SqlParameter("@Cyl",SqlDbType.VarChar,50);
                        parm3.Direction=ParameterDirection.Input;
                        parm3.Value=Cyl;

                        cmdUpdate.Parameters.Clear();
                        cmdUpdate.Parameters.Add(parm);
                        cmdUpdate.Parameters.Add(parm1);
                        cmdUpdate.Parameters.Add(parm2);
                        cmdUpdate.Parameters.Add(parm3);

                        MyCon.Open();
                        cmdUpdate.ExecuteNonQuery();
                        MyCon.Close();

                        return true;
                  }
                  catch
                  {
                        MyCon.Close();
                        return false;
                  }
                  
how can i know if the command affect on rows in the db ?
maybe the command affected only 1 row in the db or more and maybe its didint affect any rows
can i return the number of rows that affectd ....

thanks ...
0
Comment
Question by:Tech_Men
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 18013854
the function ExecuteNonQuery returns the number of rows affected:

int rows_affected = cmdUpdate.ExecuteNonQuery();
if (rows_affected == 0)
,...

0
 

Author Comment

by:Tech_Men
ID: 18013855
thanks ....
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now