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 4613968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:37:47+00:00 2026-05-22T01:37:47+00:00

I have a web site with which I am adding records to a database

  • 0

I have a web site with which I am adding records to a database and The info I am also writing to a log file which is part of the website.
The info is written to the file fine…the only question I do have is how to add information with each input into the database.
As it is at the moment the information is put int the lof file but with each new insert into the database the existing record in the log file seems to be overwritten and replaced with a new insert so that there is always only one record added to the log file.
Advice perhaps…
this is the code I used in the btnClick event.

protected void btnSubmitRating_Click1(object sender, EventArgs e)
{
    int rating = 0;
    try
    {
        if (radRating.Items[0].Selected)
        {
            rating = 1;
        }
        if (radRating.Items[1].Selected)
        {
            rating = 2;
        }
        else if (radRating.Items[2].Selected)
        {
            rating = 3;
        }
        else if (radRating.Items[3].Selected)
        {
            rating = 4;
        }
        else if (radRating.Items[4].Selected)
        {
            rating = 5;
        }
        FileStream rate = new FileStream(Server.MapPath("~/rateBooks.log"), FileMode.Open, FileAccess.ReadWrite);
        BufferedStream bs = new BufferedStream(rate);
        rate.Close();


        StreamWriter sw = new StreamWriter(Server.MapPath("~/rateBooks.log"));
        sw.WriteLine("userName " + txtUserName.Text + " " + "bookTitle " + txtBookTitle.Text + " " + "ISBN " + txtISBN.Text);
        sw.Close();


        Service s = new Service();
        s.bookRatedAdd(txtBookTitle.Text, rating, txtReview.Text, txtISBN.Text, txtUserName.Text);
        btnSubmitRating.Enabled = false;
        radRating.Enabled = false;            
    }
    catch (Exception em)
    {
        lblError.Text = em.Message; 
        //lblError.Text = "This book has already been reviewed by yourself?";
    }
}

Kind regards

  • 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-22T01:37:47+00:00Added an answer on May 22, 2026 at 1:37 am

    Change this whole block of code:

    FileStream rate = new FileStream(Server.MapPath("~/rateBooks.log"), FileMode.Open, FileAccess.ReadWrite);
    BufferedStream bs = new BufferedStream(rate);
    rate.Close();
    
    StreamWriter sw = new StreamWriter(Server.MapPath("~/rateBooks.log"));
    sw.WriteLine("userName " + txtUserName.Text + " " + "bookTitle " + txtBookTitle.Text + " " + "ISBN " + txtISBN.Text);
    sw.Close();
    

    To this single line:

    File.AppendAllText(Server.MapPath("~/rateBooks.log"), "userName " + txtUserName.Text + " " + "bookTitle " + txtBookTitle.Text + " " + "ISBN " + txtISBN.Text + Environment.NewLine);
    

    Note that I’m now adding manually NewLine to each line.

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

Sidebar

Related Questions

Here's the setup. I have web site which is essentially a simple CMS. Here
I have a web site which I download 2-3 MB of raw data from
I have a delete button on my web site which I want to add
I have a PHP5/Zend Framework 1.8.1 web site which is located at: http://www.example.com/foo The
I have a web site with an API which publishes the information using JSON.
I have an ASP.NET MVC web site. I have many actions which require authentication
I have a web page in which people go to register for my site.
I have web site which serves web services (a mixture of .asmx and WCF)
So I have an ASP.NET 'Web Site' (as opposed to a Web Application) which
I have a web creation program which, when building a site, creates hundreds of

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.