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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:48:46+00:00 2026-05-17T20:48:46+00:00

We have a dataset dsActualCost which fetches query value: MonthName in one column and

  • 0

We have a dataset dsActualCost which fetches query value: MonthName in one column and Cost in another.
We have a code to display data in table format.

 For MonthIndex = 0 To dsMonth.Tables(0).Rows.Count - 1
   Dim tdMonthlycost As New TableCell
   If dsActualCost.Tables(0).Rows.Count > 0 Then
     If IsDBNull(dsActualCost.Tables(0).Rows(MonthIndex).Item(1)) Then         
           tdMonthlycost.Text = 0
      Else
           tdMonthlycost.Text = dsActualCost.Tables(0).Rows(MonthIndex).Item(1)
      End If
    Else
      tdMonthlycost.Text = 0
    End If
       trBody.Cells.Add(tdMonthlycost)
  Next  

This code works fine when
we have data in all rows
we have no data at all

But it gives exception for all other cases.
I tried to debug and issue arises when it searches for any row which is not available in DB.

Say the dataset has only 2 rows for Feb month,so when it executes line
IsDBNull(dsActualCost.Tables(0).Rows(2).Item(1))
It throws Db null exception.

please suggest how should i handle it. the loop will run for 12 months.

  • 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-17T20:48:46+00:00Added an answer on May 17, 2026 at 8:48 pm

    Here is the code now. Do let me know if you have any suggestions:

    Dim Flag As Integer = 0  
    For MonthIndex = 0 To dsMonth.Tables(0).Rows.Count - 1  
     Dim tdMonthly As New TableCell  
         Dim CostMonth As Integer  
         Dim CostValue As Integer  
         If (dsActualCost.Tables(0).Rows.Count > 0) Then  
              If (Flag <> dsActualCost.Tables(0).Rows.Count) Then  
                   CostMonth = dsActualCost.Tables(0).Rows(Flag).Item(1)  
                    CostValue = dsActualCost.Tables(0).Rows(Flag).Item(0)  
                     If (dsMonth.Tables(0).Rows(MonthIndex).Item(0) = CostMonth Or (dsMonth.Tables(0).Rows(MonthIndex).Item(0) - 1 = CostMonth)) Then  
                          tdMonthly.Text = CostValue  
                          Flag = Flag + 1  
                     Else  
                          tdMonthly.Text = 0  
                      End If  
                 Else  
                       tdMonthly.Text = 0  
                 End If  
             Else  
                 tdMonthly.Text = 0  
            End If  
            trBody.Cells.Add(tdMonthly)  
    Next  
    

    The month in dsMonth dataset is an integer and shows only even number( like Jan-2, Feb-4 etc). But the month in dsActual shows either of 1,2 for Jan and 3,4 for feb. That is the reason I had put

     If (dsMonth.Tables(0).Rows(MonthIndex).Item(0) = CostMonth 
        Or (dsMonth.Tables(0).Rows(MonthIndex).Item(0) - 1 = CostMonth)) 
    

    Please let me know your suggestions if any.

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

Sidebar

Related Questions

I have a DataSet which has one table loaded with data. When i write
I have a DataSet named dsView that contains data. Here is the code i
i have dataset that contain data. i need to run any query on this
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
I have a DataSet which I get a DataTable from that I am being
I have a DataSet that contains a few columns. One of these columns is
I have a DataSet consisting of XML data, I can easily output this to
I have a dataset in MySQL where using limit is already an expensive query,
I have a dataset akin to this User Date Value A 2012-01-01 4 A
I have a dataset which I want to use as a parameter for my

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.