Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-26
2
Medium Priority
?
231 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1200 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

927 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