Solved

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

Posted on 2006-11-26
2
198 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

21 Experts available now in Live!

Get 1:1 Help Now