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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:33:16+00:00 2026-05-26T18:33:16+00:00

I need to add new records to my SQL database using C# and php.

  • 0

I need to add new records to my SQL database using C# and php. I’m using this code:

string server = "http://www.naseelco.com/scorm/populatecode.php";
foreach (string code in codeList)//codelist has 200 items
 {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(server);
     request.Method = "POST";
     string postData = "Code=" + code + "&Active=false";
     byte[] byteArray = Encoding.UTF8.GetBytes(postData);
     request.ContentType = "application/x-www-form-urlencoded";
     request.ContentLength = byteArray.Length;
     try
     {
         Stream dataStream = request.GetRequestStream();
         dataStream.Write(byteArray, 0, byteArray.Length);
         dataStream.Close();
     }
     catch
     {

     }
}

This is the content of the populatecode.php file:

<?php 
$Code = $_POST['Code'];
$Active = $_POST['Active'];
mysql_connect("localhost","myUserName","myPassword") or die ('Error updating database');
mysql_select_db("naseelc1_AC");
mysql_query("INSERT INTO codes (code,Active)VALUES ('$Code','$Active')");
echo $Code;
?>

But this code takes too much time to update the SQL database. My question is:
Is there a more efficient way to insert multiple records in a SQL database?

  • 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-26T18:33:17+00:00Added an answer on May 26, 2026 at 6:33 pm

    The first thing when analyzing performance problems is to test and verify where you lose the time, not to assume that it’s one special part of your system.

    You say “takes too much time to update the SQL database“, how do you know it’s the INSERTs that are slowing you down?

    First you have to measure the runtime of each part of your system. Then optimize that part.

    Do not start optimization if you don’t know which part to optimize.

    Use a profiler or simple time measuring code using microtime() in PHP and the Stopwatch class in C# to calculate the runtime of a piece in your program to pinpoint the hotspots.

    Assuming you have done all that and still find that `INSERTìng a single row is taking too long, then there are several areas to explore. Too many indexes is probably the first thing to check.

    Seeing your program, I’d bet that Anders Abel is right and you are losing your time in the HTTP overhead, not during INSERTs

    An alternative approache would be to send the whole list to the PHP code and then using a multi-row INSERT to insert everything with just a single statement:

      INSERT INTO codes (code,Active)
      VALUES 
      ('code_1', true),
      ('code_2', false),
      ('code_3', true),
      ('code_4', false),
      ('code_5', true)
    

    But I still believe it’s your concept of sending each code as one POST to the backend that is taking all the time…

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

Sidebar

Related Questions

I need to add a new column to a MS SQL 2005 database with
I need to add default value column in SqlServer Compact....i am new to this
I need add a new user group for mediawiki. The new group has more
I need to add a new SELECT statement whose search condition include something like
After inserting new html to DOM,I need to add some listeners to it. But
I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity
I am doing some performance tests using .Net 3.5 against SQL Server. I am
I'm importing an Excel file (about 1000 records only) to a dedicated SQL Server
Our server application receives information about rows to add to the database at a
I have some database table and need to process records from it 5 at

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.