Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:31:11+00:00 2026-06-17T20:31:11+00:00

I’ve got an ASP.NET 4.0 C# web application that allows multiple users to update

  • 0

I’ve got an ASP.NET 4.0 C# web application that allows multiple users to update rows in the SQL Server DB at the same time. I’m trying to come up with a quick system that will stop USER1 from updating a row that USER2 updated since USER1’s last page refresh.

The problem I’m having is that my web application always updates the row, even when I think it shouldn’t. But when I manually run the query it only updates when I think it should.

This is my SQL query in C#:

SQLString = "update statuses set stat = '" + UpdaterDD.SelectedValue +
            "', tester = '" + Session["Username"].ToString() +
            "', timestamp_m = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") +
            "' where id IN (" + IDs + ") and timestamp_m < '" + PageLoadTime + "';";

And here’s a ‘real world’ example:

SQLString = "update statuses set stat = 'PASS', tester = 'tester007',
             timestamp_m = '2013-01-23 14:20:07.221' where id IN (122645) and
             timestamp_m < '2013-01-23 14:20:06.164';"

My idea was that this will only update if no other user has changed this row since the user last loaded the page. I have formatted PageLoadTime to the same formatting as my SQL Server DB, as you can see with DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), but something still isn’t right.

Does anyone know why I get two different results? Is what I want to do even possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:31:12+00:00Added an answer on June 17, 2026 at 8:31 pm

    I really think the problem is that the page load time is not being set correctly, or is being set immediately before the DB call. For debugging, you may try hardcoding values into it that you know will allow or disallow the insert.

    Here’s a parameterized version of what you have. I also am letting the DB server set the timestamp to its current time instead of passing a value. If your DB server and your Web server may not have their time of day in synch, then set it yourself.

    Using parameterization, you don’t have to worry about whether the date/time format is correct or not. I don’t know what the DB types are of stat, tester, and timestamp_m so adding the parameter DB type may need adjusting.

    string sql = "update statuses set stat = @stat, tester = @tester" +
            ", timestamp_m = getdate()" +
            " where id IN (" + IDs + ") and timestamp_m < @pageLoadTime";
    
    SQLConnection conn = getMeASqlConnection();
    
    SQLCommand cmd = new SQLCommand(sql, conn);
    
    cmd.Parameters.Add("@stat", System.Data.SqlDbType.NVarChar).Value = UpdaterDD.SelectedValue;
    cmd.Parameters.Add("@tester", System.Data.SqlDbType.NVarChar).Value = Session["Username"].ToString();
    // Here, pageLoadTime is a DateTime object, not a string
    cmd.Parameters.Add("@pageLoadTime", System.Data.SqlDbType.DateTime).Value = pageLoadTime;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.