Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.8k

Find max value in column and icrease for 1...

Mar 12 2018 7:19 AM
Why update complete column...not just active cell
 
  1. SqlDataReader rdr;  
  2.                            SqlCommand cmd = new SqlCommand();  
  3.   
  4.   
  5.                            cmd.CommandText = "select max(brojprijavnice2) from dbo.prijava_radnika WHERE radnik = '" + readerresultTextbox.Text + "'";   
  6.                            cmd.Connection = con;  
  7.                            con.Open();  
  8.                            rdr = cmd.ExecuteReader();  
  9.                            int max = 0;  
  10.                            while (rdr.Read())  
  11.                            {  
  12.                                max = Convert.ToInt32(rdr[0].ToString());  
  13.                                Console.WriteLine(max);  
  14.   
  15.                            }  
  16.                            con.Close();  
  17.   
  18.   
  19.                            String updateStaff = "UPDATE [dbo].[prijava_radnika] SET [vrijemeodjave] = @vrijemeodjave, brojprijavnice2 = " + (max + 1) + ", [status] = 'odjavljen' WHERE radnik = '" + readerresultTextbox.Text + "'"
 

Answers (4)