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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:26:44+00:00 2026-05-16T05:26:44+00:00

Problem is when I add second datarow to dataset. If I remove // comments

  • 0

Problem is when I add second datarow to dataset. If I remove // comments I only get 1 row add instead of 80

SqlDataAdapter indicatorsExp = new SqlDataAdapter();
string sqlExp = "SELECT * FROM BusinessApplications.tbl_WPI_Site_Indicators_Exp " +
                "where Year = '" + year + "' and  Month = '" + month + "'";
indicatorsExp.SelectCommand = new SqlCommand(sqlExp, conn);
SqlCommandBuilder cbexp = new SqlCommandBuilder(indicatorsExp);
indicatorsExp.InsertCommand = cbexp.GetInsertCommand();
DataSet dsExp = new DataSet();
indicatorsExp.Fill(dsExp, "explanations");
DataTable explanations = dsExp.Tables["explanations"];

//.......
foreach (ISite site in sites)
{
    DataRow drexp1 = explanations.NewRow();
    try
    {
        drexp1["PlantId"] = site.ID;
        drexp1["Month"] = month;
        drexp1["Year"] = year;
    }
    catch { }
    DataRow drexp2 = explanations.NewRow();
    try
    {
        drexp2["PlantId"] = site.ID;
        drexp2["Month"] = month;
        drexp2["Year"] = year;
    }
    catch { }

    explanations.Rows.Add(drexp1);
    indicatorsExp.Update(dsExp, "explanations");
//    explanations.Rows.Add(drexp2);
//    indicatorsExp.Update(dsExp, "explanations");

    }
  • 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-16T05:26:44+00:00Added an answer on May 16, 2026 at 5:26 am

    1 – if that Select * is really in your code, fix it.
    2 – You really need to wrap the Rows.Add() and Update() statements in Try/Catch as well as what you’re doing. I’d normally use one try/catch for the whole thing, and I certainly wouldn’t swallow the exceptions as you’re doing.

    With those said, It’s hard from your question to understand exactly what you’re doing. After making the two above fixes, I’d also change this:

    explanations.Rows.Add(drexp1);
    explanations.Update(dsExp, "explanations");
    explanations.Rows.Add(drexp2);
    explanations.Update(dsExp, "explanations");
    

    to this:

    explanations.Rows.Add(drexp1);
    explanations.Rows.Add(drexp2);
    explanations.Update(dsExp, "explanations");
    

    With (especially) the last two changes (only call Update once, and actually handle your exceptions, even if you’re just re-throwing them) you may fix the problem. At the very least, you should get better information about what the actual problem is so it can be located and corrected.

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

Sidebar

Ask A Question

Stats

  • Questions 481k
  • Answers 481k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Actually, yes, it is possible to bypass the constructor when… May 16, 2026 at 6:27 am
  • Editorial Team
    Editorial Team added an answer Oracle DATE datatype is a point in time, it has… May 16, 2026 at 6:27 am
  • Editorial Team
    Editorial Team added an answer No, no error will be thrown. You will have a… May 16, 2026 at 6:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.