Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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