0

Hey there, i would like to find out how many records have been modified by my quarry.
I tried a few things, but none would work.
this is my code

SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=.\\SQL2008;database=Studentsdb1;Persist Security Info=True;user id=sa;password=1945";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            String SQL = String.Format("UPDATE StudentsTable SET  Account_Amount = '{0}'   WHERE Account_Amount = '{1}'", txtchangeto.Text, txtChangeFrom.Text);
            btnSave.Text = cmd.CommandText.ToString();

            cmd.CommandText = SQL;
            
            cmd.Connection = conn;

            object result = null;
            ConnectionState previousConnectionState = conn.State;
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                result = cmd.ExecuteScalar();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    conn.Close();
                }
            }

HOw would i put the amount of records changed into textboxAmountChanged?

txtboxAmountChanged.Text = "i have no clue"....\

Thank you =)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Mr.BunyRabit
0

Line 20 should be ExecuteNonQuery, which returns the number of records changed.

Thank you. Was very helpful. =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.