locked
problem with counting number of hits per item C# RRS feed

  • Question

  • User-1283384789 posted

     Hi,

    I have this code that counts # of hits. It works, but i noticed that if you go for exmaple to item # 2 it shows 5 hits, then when i go to item #3 and return back to item # 2 it shows 7 hits instead of 6.

    This is my code:

     

    protected void DataList3_Load(object sender, EventArgs e)
      {
    
          Label hits = DataList3.FindControl("hits") as Label;
    
          string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Orozje-Reloading-Center.mdb";
          OleDbConnection conn = new OleDbConnection(connectionString);
          conn.Open();
          OleDbCommand cmd = new OleDbCommand();
          cmd.Connection = conn;
          cmd.CommandText = "SELECT * FROM [NABOJI_POLNITVE] WHERE PID = ?";
          cmd.CommandText = "UPDATE NABOJI_POLNITVE SET hits = hits + 1";
          cmd.Parameters.Add("@hits", OleDbType.Integer).Value = hits;
          cmd.ExecuteNonQuery();
          conn.Close();
      }

      

    Not sure what to change so it will show corect count.

    Thanks

    Tuesday, June 16, 2009 5:22 AM

All replies

  • User-2119480821 posted

    put breakpoint and debug the code line by line, vr it gets fails..

    Tuesday, June 16, 2009 6:50 AM
  • User-1283384789 posted

     i tried debug it but i didnt get any error messages. Problem is that in my case it counts a hit on item #2 even though i was on item #3.

    Tuesday, June 16, 2009 7:39 AM