Results 1 to 6 of 6

Thread: Ok this makes no sense. Solved Somewhat

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    127

    Ok this makes no sense. Solved Somewhat

    I posted all the code for the database transaction, maybe I have just been looking at it way too long but what the heck is going on. look at that page count variable especially. Simply add 1 to it. or so I think, for some reason no matter what I do it adds 2. I can;t figure this out, This is in a constructor for a class. that is just supposed to be indexing a counter and getting some data. I have tried everything I can think of but it keeps advancing 2. Anyone have any idea why. even if imediately right after that line I write out the result it is 2 more than what it was before, it is like the code is running twice but why? No I am not newing it up 2 times or anything in fact it is the only line of code on the web page, this is behind the scenes in an assembly


    Code:
    string SQLSelect = "Select PagePath,PageTitle,PageClass,HitCount,SecurePage,Maintenance From PageData Where PagePath = '" + RelativeURL + "'";
    System.Data.SqlClient.SqlCommand CMD = new System.Data.SqlClient.SqlCommand(SQLSelect,DataBaseConnection);
    System.Data.SqlClient.SqlDataReader RS = CMD.ExecuteReader();
    
    if (RS.HasRows)
    {
         RS.Read();
         pageTitle = RS.GetString(1);
         pageClass = RS.GetString(2);
         PageCount = RS.GetInt32(3) + 1; //this line here is the pain
         PageSecureDB = RS.GetString(4);
         PageMaintDB = RS.GetString(5);
         if (PageSecureDB.ToLower() != "yes")
         {
              pageSecure = false;
         }
         if (PageMaintDB.ToLower() != "yes")
         {
              pageMaintenance = false;
         }
         RS.Close();
         SQLSelect = "UPDATE PageData Set HitCount = " + PageCount.ToString() + " Where PagePath = '" + RelativeURL + "'";
         CMD = new System.Data.SqlClient.SqlCommand(SQLSelect,DataBaseConnection);
         CMD.ExecuteNonQuery();
    }
    else
    {	
         RS.Close();
         SQLSelect = "INSERT INTO PageData (PagePath,PageTitle,PageClass,HitCount,SecurePage,Maintenance) VALUES ('" + RelativeURL + "','" + pageTitle + "','" + pageClass + "'," + PageCount.ToString() + ",'yes','yes')";
         CMD = new System.Data.SqlClient.SqlCommand(SQLSelect,DataBaseConnection);
         CMD.ExecuteNonQuery();
    }
    Last edited by BOUND4DOOM; Jun 30th, 2003 at 02:18 PM.
    The secret to creativity is knowing how to hide your sources.
    -- Albert Einstein

  2. #2

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    127
    Oh yeah and I forgot to mention if I remove the + 1 it doesn;t count up at all, if I leave the + 1 it adds 2, I have tried declairing the variable as just the number 1 then then used
    PageCount += RS.GetInt32(3)

    but I get the same result it adds 2.
    The secret to creativity is knowing how to hide your sources.
    -- Albert Einstein

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I had the same thing happen to me also. I forgot what I was doing, but I couldn't ever figure out why it was doing it. I know that isn't much help. Try this, it should work by breaking it down to two lines.

    PageCount = RS.GetInt32(3)
    PageCount++

    or
    PageCount = RS.GetInt32(3)
    PageCount += 1

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    127
    Already tried that really a frustrating problem I can figure out where it is counting 2 times from. if I break it into 2 lines it still counts 2, if I rem out the line that counts then it doesn;t count at all.
    The secret to creativity is knowing how to hide your sources.
    -- Albert Einstein

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    127
    Ok now lets add to the confusion some more, I pulled the entire web project down to my PC to see if I could debug it and see what the values are at any time and see if it is executing twice, first thing I do after copying it is test it. It works just fine. only counting by one. I run it on the server and it is counting by 2. The exact same dll code. I am really stuck here.
    The secret to creativity is knowing how to hide your sources.
    -- Albert Einstein

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    127
    Solved.

    I had AutoEventwireup turned on. which it is on by default however it is what was causing the problems. it was causing my code to be executed twice. I am still unclear as to why AutoEventWireup does this. if anyone known please let me know.
    The secret to creativity is knowing how to hide your sources.
    -- Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width