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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:47:15+00:00 2026-06-06T04:47:15+00:00

I am writing my C# application that connects to database, does couple selects and

  • 0

I am writing my C# application that connects to database, does couple selects and then inserts record back to the server in the network.

But I have around 40k records and my program processes one records like for 1 second.

I don’t know how to improve the performance. Here are my sql getter and inserter. Any suggestions?

    public bool insert_and_ConfirmSQL(String Query, String comments)
    {
        bool success = false;
        NpgsqlCommand cmd = new NpgsqlCommand();
        NpgsqlConnection mycon = new NpgsqlConnection();
        string connstring = String.Format("Server={0};Port={1}; User Id={2};Password={3};Database={4};", tbHost, tbPort, tbUser, tbPass, tbDataBaseName);
        mycon.ConnectionString = connstring;
        cmd = mycon.CreateCommand();
        cmd.CommandText = Query;
        mycon.Open();

        int temp = 0;
        try
        {
            temp = cmd.ExecuteNonQuery();
            success = true;
        }
        catch
        {
            success = false;
        }
        finally
        {
            if (mycon.State.ToString() == "Open")
            {
                mycon.Close();
            }
        }
        return success;
    }


    public String getString(String sql, NpgsqlConnection conn)
    {
        using (DataSet ds = new DataSet())
        {
            using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn))
            {
                da.Fill(ds);
                if (ds.Tables.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    //  check count of Rows 
                    if (dt.Rows.Count > 0)
                    {
                        object o = dt.Rows[0][0];
                        if (o != DBNull.Value && o != null)
                        {
                            return o.ToString();
                        }
                    }
                }
            }
        }
        // Return default value 
        return "";
    }
  • 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-06T04:47:16+00:00Added an answer on June 6, 2026 at 4:47 am

    Sometimes you can improve performance by using a sql Datareader instead of DataSets.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader(v=vs.100).aspx#Y0

    You then can Inspect the data while you are reading it from the database.

    So I’d implement the above code with a DataReader and retime it.

    Edit: Especially that getString method. if that ds.Fill was taking 40k rows that could be the cause of your performance problem.

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

Sidebar

Related Questions

I'm writing a software application in C#.Net that connects to a SQL Server database.
I'm writing a database application that connects to SQL server. I'd like to implement
I am writing a C# console application that connects to a server trough TCP,
I am writing a TCP server application using Winsock. The client that connects to
I am writing a Java JDBC database application that connects to an Oracle 11g
I'm writing a web application that connects to a database. I'm currently using a
Im writing an application that supposed to send coordinates in an SMS, but I've
I am writing a Windows application that will connect to a Sybase database through
I'm writing an application that allows users to upload images onto the server. I
I am writing an application that needs to connect to a MySQL database on

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.