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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:37:52+00:00 2026-06-06T07:37:52+00:00

I have an SQL query like this: set @fromdate = ‘2012/01/01 00:00:00’ set @todate

  • 0

I have an SQL query like this:

set @fromdate = '2012/01/01 00:00:00'
set @todate = '2013/01/01 00:00:00'

SELECT TableOne.date_time, TableTwo.* 
FROM TableOne 
INNER JOIN TableTwo ON TableOne.gprs_id = TableTwo.recordid 
WHERE date_time >= @fromdate AND date_time <= @todate

I use it in .net 4 (c#) like this:

string strSQL = "SELECT TableOne.date_time, TableTwo.* FROM TableOne INNER JOIN TableTwo ON " +
                "TableOne.gprs_id = TableTwo.recordid where date_time >= @fromdate AND date_time <= @todate";

var pCommand = pConnectionWrapper.DBConnection.CreateCommand();
pCommand.CommandText = strSQL;

var paramFromDate = pCommand.CreateParameter();
paramFromDate.ParameterName = "@fromdate";
paramFromDate.DbType = DbType.DateTime;
paramFromDate.SourceColumn = "date_time";
paramFromDate.Value = fromDate;
pCommand.Parameters.Add(paramFromDate);

var paramToDate = pCommand.CreateParameter();
paramToDate.ParameterName = "@todate";
paramToDate.DbType = DbType.DateTime;
paramToDate.SourceColumn = "date_time";
paramToDate.Value = toDate;
pCommand.Parameters.Add(paramToDate);

var pReader = pCommand.ExecuteReader();

while (pReader.Read())
{
   var someValue = double.Parse(pReader["somevalue"].ToString());
   var date = DateTime.Parse(pReader["date_time"].ToString());

   var someObject = new someObject(someValue, someDate);
   someObjects.Add(comeObject);
}

Running this query is much faster in SQL Server Management Studio than from .net. Iterating through rows is extremely slow from .net. As I think this inner join causes this (?), because my other queries that does not contain joins are really fast under .net.

Can I improve the query performance from .net? Using datasets instead of reader or sg like this?

Thank you very much!

  • 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-06T07:37:54+00:00Added an answer on June 6, 2026 at 7:37 am

    This will not really fix the query but will get the data from the query more efficiently.
    Return only the columns you need by name. Reader should be faster than a dataset.

    Double someValue;
    DateTime date;
    while (pReader.Read())
    {
       someValue = pReader.GetDouble(0);
       date = pReader.GetDate(1);
    
       var someObject = new someObject(someValue, someDate);
       someObjects.Add(comeObject);
    }
    
    //or
    while (pReader.Read())
    {
       someObjects.Add(new someObject(pReader.GetDouble(0), pReader.GetDate(1)));
    }
    

    As for the query it seems pretty basic.

    Comment out the 2 object lines to see if that is possibly the bottleneck.

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

Sidebar

Related Questions

I have a SQL query like this: SET @q = (SELECT Id AS '@Id',
I have a SQL query that goes like this: UPDATE User SET flag='Y' WHERE
I have a query like this: UPDATE t3 SET somevalue = (SELECT t2.id FROM
I have built a T-SQL query like this: DECLARE @search nvarchar(1000) = 'FORMSOF(INFLECTIONAL,hills) AND
I have a SQL query in my ASP.net web app that looks like this:
In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights
I have this SQL query select case when AllowanceId is null then 2 else
I have this sql query: SELECT S.SEARCH, S.STATUS, C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine,
I have a SQL query running using something like this: PreparedStatement pstmt = dbConn.prepareStatement(sqlQuery);
Suppose we have a simple query like this: SELECT x FROM t WHERE t.y

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.