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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:12:10+00:00 2026-05-23T16:12:10+00:00

I am trying to get the database values and binding to data table by

  • 0

I am trying to get the database values and binding to data table by using the following query

sql = @"SELECT member_Id, 30*memberToMship_ChargePerPeriod  / DateDiff(memberToMship_EndDate, 
         memberToMship_StartDate) As monthlyamount,
         PERIOD_DIFF(DATE_FORMAT(now(),'%Y%m'), 
         DATE_FORMAT(memberToMship_StartDate,'%Y%m'))  + (DAY(memberToMship_StartDate) < memberToMship_DueDay)+ (DAY(now()) > memberToMship_DueDay)-1  AS ExpPayments, 
         SUM(memberToMship_InductionFee+memberToMship_JoinFee+
             (IF(mshipOption_Period='year',
             TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
             TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod)) as value 
        FROM membertomships 
        INNER JOIN mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipoption_Id";

and this is my code for getting the data to datable from database

string memberid;
double value = 0.0;
double expectedpayment=0.0;
double monthlypayamount=0.0;
int dueday = 0;

dt = xxxxxx.GetData(sql, mf);    
if (dt != null && dt.Rows.Count > 0)
{
      memberid = Convert.ToInt32(dt.Rows[0]["member_Id"]).ToString();
      monthlypayamount = Convert.ToDouble(dt.Rows[1]["monthlyamount"]);
      expectedpayment = Convert.ToDouble(dt.Rows[2]["ExpPayments"]);
      value = Convert.ToDouble(dt.Rows[3]["value"]);       
}

but I am getting an error

” index out of range exception”

and error like this

“there is no row at position 1”

Would any one please help on this…

  • 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-23T16:12:10+00:00Added an answer on May 23, 2026 at 4:12 pm

    You should use index [0] for Rows on every line of code if you want to get all the data from the first row that was returned. If you use Rows[1] and Rows[2] etc., then you are looking at the second row, and third row, etc., which is invalid if your query only returned one row of data.

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

Sidebar

Related Questions

I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I'm trying to get the Score_Waarde value from my database using the following code
I'm still trying to get my head around LINQ and accessing a SQL Database.
I'm trying to get a value from one of my database values, which will
So I'm trying to get the values from a SQLite database into a cursor,
I am trying to add data to a database, in grails but get this
I'm trying to get my head round this mind boggling stuff they call Database
I'm trying to run some queries to get rid of XSS in our database
I'm trying to get a WCF service set up on our server using windows
I have a DataGridView that displays data from a MS Access database. I'm using

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.