forum

Home / DeveloperSection / Forums / code optimized in c#

code optimized in c#

Anonymous User 3241 16-Nov-2012
hello every one,

public static int SetSelectedItem(string[] sValues)
        {
            int nRow = 0;
            try
            {
                foreach (string str in sValues)
                {
                    SqlCommand cmdUpdate = new SqlCommand("UPDATE [dbo].[tblProductsManager] SET IsActive = 1 WHERE Id= '" + str + "' ", con);
                    if (con.State == ConnectionState.Closed)
                        con.Open();
                    nRow = cmdUpdate.ExecuteNonQuery();
                }
            }
            catch { }
            finally
            {
                if (con.State == ConnectionState.Open)
                    con.Close();
            }
            return nRow;
        }

in the above code, "cmdUpdate.ExecuteNonQuery();" call for every value of "sValues".

i want, "cmdUpdate.ExecuteNonQuery();" execute only one time for all array value.
if have any idea, plz help me.

c# c# 
Updated on 19-Nov-2012
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By