?
Solved

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

Posted on 2006-11-26
2
Medium Priority
?
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

719 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