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

  • SEARCH
  • Home
  • 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 4617856
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:11:01+00:00 2026-05-22T02:11:01+00:00

i building a mini forum site.. and i constructed a few tables. 1) Users

  • 0

i building a mini forum site.. and i constructed a few tables.

1) Users
2) Threads
3) Comments
4) Topics

i build a function that would insert a comment each time a user would submit a comment:

         string saveComment = "INSERT INTO Comments(";
     saveComment += " UsersID, ThreadsID, Date, Comments, CommentResponse";


     saveComment += "Values('" + "','";// no idea what to insert in the UsersID
     saveComment += "" + "','";// no idea what to insert in the ThreadsID

     saveComment += DateTime.Now + "','";
     saveComment += CommenttxtBox.Text + "','";
     saveComment += commentResponseString + "')";

As you can see the fields have UsersID and ThreadID, both connected by a foreign key to the comments table.
Now, each time the user submits a comment, i guess i need to insert also to the UsersID field (which is an int in the comments table, and that field increases incrementally by 1 in the Users table). How can i insert a comment, and notify the other table not to increase the UserID by 1. in fact i want it the UserID to stay the same for each user submitting a comment..

How do i do that? i need to insert to a few fields in one table (comments) but keep the other tables informed that it is actually the same user who submitted the comment .

Note: i dont know any vb, only c#, and i use visual studio 2010. asp.net

  • 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-05-22T02:11:02+00:00Added an answer on May 22, 2026 at 2:11 am

    You are creating a very standard normalised structure. Your Users table will be responsible for controlling the UserID values that are generated.

    You have two situations to cope with when inserting new comments:

    1. The User exists and is logged in.
    2. The User does not exist and is anonymous.

    In the first situation, when you are inserting the comments you will not need to bother looking at the Users table. This assumes you have the UserID already loaded (as the user is logged in).

    In the second situation, you will first need to a new row to the Users table and return the UserID that the table generates (assuming you are using an identity column). You can then pass this value to the Comments table.

    The following script is an example of addressing the second situation:

    DECLARE @userId int
    
    INSERT INTO Users (Username, FirstName)
    VALUES ('adamh', 'Adam')
    
    SET @userId = SCOPE_IDENTITY()
    
    INSERT INTO Comments(UserId, ThreadId, Comment)
    VALUES (@userId, 1, 'My comment')
    

    If you want to continue with your current coding style, simply concatenate the values into the relevant parts of the string.

    However, with such as neatly defined structure as the one you have, I’d advise using something like Entity Framework 4.0, or LINQ to SQL, which cuts a lot of plumbing out once you have defined your structures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a mobile site and wanted to create a rotator that would work just
building a site using PHP and MySQL that needs to store a lot of
Building a website that has English & Japanese speaking users, with the Japanese users
Building an iPhone OS application that will allow users to anonymously post information to
We are looking on building a project that would run on Android, iPhone and
Building a rails B2B application that will have various users. I'm pretty clear on
I'm building a mini news CMS where the news added are sorted using a
Building a new Mobile Web Platform for Mobile Users to purchase & download content
Building a commercial product may use various open source libraries that have use of
Building a site super quick and having it work on all my Mac browsers,

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.