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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:24:48+00:00 2026-05-31T17:24:48+00:00

I’m using C# to input and output multi 2d arrays into SQL database. The

  • 0

I’m using C# to input and output multi 2d arrays into SQL database.
The 2D array is something like :

Pt[100,50]={0.3,0.2,0.1,...,0.8;
            0.2,0.5,0.5,...,0.1;
            .    .
            .    .
            .    .

            0.1,0.6,0.5,...,0.2}

I know to design a (index_x,index_y) table in SQL and use two loops on C# to get it done.

Is there an better way to input and output the 2D array more efficiently?

Any examples would be great!

  • 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-31T17:24:49+00:00Added an answer on May 31, 2026 at 5:24 pm

    By executing a separate SQL statement at each point, you are doing as many database round-trips as there are points to insert. Each round-trip incurs a communication latency (especially if the database is not local) as well as some bookkeeping costs at the level of the DBMS.

    The crude and not very scalable, but database-agnostic way to perform multiple inserts within only one database round-trip is to simply pack multiple INSERT statements into a single DbCommand object.

    Assuming your table looks similar to this (use your DBMS-specific types as appropriate)…

    CREATE TABLE YOUR_TABLE(
        INDEX_X int NOT NULL,
        INDEX_Y int NOT NULL,
        VALUE numeric(18, 4) NOT NULL,
        PRIMARY KEY ( INDEX_X, INDEX_Y )
    )
    

    …here is one way to do it:

    class Program {
    
        static void Main(string[] args) {
    
            double[,] pt = {
                { 0.3, 0.2, 0.1, 0.8 },
                { 0.2, 0.5, 0.5, 0.1 },
                { 0.1, 0.6, 0.5, 0.2 }
            };
    
            // Replace SqlConnection with what is specific to your ADO.NET provider / DBMS.
            using (var conn = new SqlConnection("your connection string")) {
    
                conn.Open();
    
                using (var cmd = conn.CreateCommand()) {
    
                    // Construct SQL text (use parameter prefix specific to your DBMS instead of @ as appropriate).
                    var sb = new StringBuilder();
                    for (int y = 0; y < pt.GetLength(0); ++y)
                        for (int x = 0; x < pt.GetLength(1); ++x)
                            sb.Append(
                                string.Format(
                                    "INSERT INTO YOUR_TABLE (INDEX_X, INDEX_Y, VALUE) VALUES (@index_x_{0}_{1}, @index_y_{1}_{1}, @value_{0}_{1});",
                                    x,
                                    y
                                )
                            );
    
    
                    cmd.CommandText = sb.ToString();
    
                    // Bind parameters.
                    for (int y = 0; y < pt.GetLength(0); ++y)
                        for (int x = 0; x < pt.GetLength(1); ++x) {
                            cmd.Parameters.AddWithValue(string.Format("@index_x_{0}_{1}", x, y), x);
                            cmd.Parameters.AddWithValue(string.Format("@index_y_{0}_{1}", x, y), y);
                            cmd.Parameters.AddWithValue(string.Format("@value_{0}_{1}", x, y), pt[y, x]);
                        }
    
                    // Perform the actual insert.
                    cmd.ExecuteNonQuery();
    
                }
    
            }
    
        }
    
    }
    

    There are more efficient, but DBMS-specific solutions, such as:

    • Oracle:
      • Array bound parameters.
      • OracleBulkCopy.
      • A stored procedure that receives array as input.
    • MS SQL Server:
      • SqlBulkCopy.
      • A stored procedure that receives XML or table-valued parameters as input.
    • Etc…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.