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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:14:37+00:00 2026-06-13T16:14:37+00:00

Using MS Visual Studio 2012 Express, Using C#.NET 4.0. Hi guys, This I believe

  • 0

Using MS Visual Studio 2012 Express, Using C#.NET 4.0.

Hi guys, This I believe is a simple one.

I’ve been rushing a program at the request of my boss, But now it turns out that I have a lot more free time on it.

So I’m going through the code trying to make it more compact, cleaner etc.

I have this one function…..

public void RunMonth()
{
    //** top 10 listings*********************//            
    SetTxtBox1(DateTime.Now.ToString() + " ==== END OF MONTH REPORTS starting.........\r\n");
    SetTxtBox1(" **************************************************************************************\r\n");
    try
    {
        VRMtableDESC = querys.TopVRM("DESC");
        SetTxtBox1(DateTime.Now.ToString() + " ==== VRM Top has been loaded\r\n");
    }
    catch
    {
        SetTxtBox1(DateTime.Now.ToString() + " ==== VRM Top has FAILED\r\n");
    }
}

“VRMtableDESC” is a datatable, one of around 18 datatables. for each datatable this try statement is run.

Now as you can tell this currently is repeated 18 times for every table.
instead i would like to loop into the tables instead and fill them with there data.

is there a way to do this? i would need some sort of collection for the datatables and the query.function calls too as far as I’m aware.

So far i have hit a blank so im hoping there is something im missing.

Thanks in Advance

::::UPDATE::::
Ok so I have this set up so far….

 foreach (DataTable tbl in MyDataSet.Tables)
 {
     tbl.TableName.Equals(querys.TopVRM(""));
 }

the equals method needs to be dynamic in its method selection too…. any ideas?

::UPDATE(31/10/12)::

Hi again, Im getting an error, the common error ” object not sent to instance of object”

it apears on the merge in the foreach loop.

I have debugged my query call and looks fine.

 var tables = new SortedDictionary<string, Func<DataTable>>()
        {
            {"VRMtableDESC",  () => querys.TopVRM("DESC")},
            {"VRMtableASC",   () => querys.BotVRM("ASC")},
            {"SpectableDESC", () => querys.TopSpec("DESC")},
            {"SpectableASC",  () => querys.botSpec("ASC")},
            {"ParttableDESC", () => querys.TopPart("DESC")},
            {"ParttableASC", () => querys.BotPart("ASC")},
            {"MantableDESC",  () => querys.TopManual("DESC")},
            {"MantableASC",   () => querys.BotMan("ASC")}, //why is this first to run?????
            {"UsersLockedTbl",() => querys.UserLocked()},
            {"NewUsersTbl",   () => querys.NewUsers()},

            {"VRMtotaltblTOP",   () => querys.VRMtotalTOP("")},
            {"PARTtotaltblTOP",  () => querys.PARTtotalTOP("")},
            {"SPECtotaltblTOP",  () => querys.SPECtotalTOP("")},
            {"MANtotaltblTOP",   () => querys.MANtotalTOP("")},
            {"VRMtotaltblBOT",   () => querys.VRMtotalBOT("")},
            {"PARTtotaltblBOT",  () => querys.PARTtotalBOT("")},
            {"SPECtotaltblBOT",  () => querys.SPECtotalBOT("")},
            {"MANtotaltblBOT",   () => querys.MANtotalBOT("")},
        };

        foreach(var kvp in tables)
        {
            try
            {
                MyDataSet.Tables[kvp.Key].Merge(kvp.Value());//error occurs here
                SetTxtBox1(String.Format("{0} ==== {1} has been Loaded\r\n", DateTime.Now.ToString(), kvp.Key));
            }catch(Exception e)
            {
                SetTxtBox1(String.Format("{0} ==== {1} has FAILED\r\n", DateTime.Now.ToString(), kvp.Key));
                MessageBox.Show("error:::" + e);
            }
        }
        AutoRunApp();  

any help would be great.

UPDATE::

heres my query call from the “bunchofquerys” class

 public DataTable BotMan(string order)
    {

            SqlConnection conn = new SqlConnection(myConnString32);
            SqlCommand vrm = new SqlCommand();
            //BindingSource bindme = new BindingSource();
            SqlDataAdapter adapt1 = new SqlDataAdapter(vrm);
           // DataSet dataSet1 = new DataSet();
            DataTable table1 = new DataTable();
            try
            {
            vrm.Connection = conn;
            vrm.CommandType = CommandType.StoredProcedure;
            if (order.Equals("DESC"))
            {
                vrm.CommandText = "dbo.TopManual";
            }
            vrm.CommandText = "dbo.BotManual";
            vrm.CommandTimeout = 360;

            vrm.Parameters.AddWithValue("@OrderBy", order);
            adapt1.Fill(table1);
            return table1;
        }
        catch (Exception e)
        {
            MessageBox.Show("eeror::zomg:::  " + e);

        }
        return table1;
    }
  • 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-13T16:14:38+00:00Added an answer on June 13, 2026 at 4:14 pm

    You said you already have a DataSet. An easy way to fill all the tables is to use Merge.

    In this example, I create a mapping between the table names (the name of the table in the DataSet), and the corresponding query function (assuming that they return a DataTable with a similar schema, and your DataSet is named ds).

    The Key is used to query the appropriate DataTable from the DataSet, and then the Merge method is used to “fill” the DataTable.

    var tables = new SortedDictionary<string, Func<DataTable>>() //or use List of Tuples... 
    {
        {"VRM_TOP",    () => querys.TopVRM("DESC")},
        {"FooBar_TOP", () => querys.FooBar("DESC")},
        {"Something",  () => querys.Something("ASC")},
    };
    
    foreach(var kvp in tables)
        ds.Tables[kvp.Key].Merge(kvp.Value());
    

    You could do it the other way round and iterate over each table in you DataSet and get the appropriate loader function via the table’s TableName.

    Your try/catch block can now easily be added to the foreach loop.

    foreach(var kvp in tables)
    {
        try
        {
            ds.Tables[kvp.Key].Merge(kvp.Value());
            SetTxtBox1(String.Format("{0} ==== {1} has ben loaded\r\n", DateTime.Now, kvp.Key));
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning ASP.Net MVC; I'm using Visual Studio Express 2012 with MVC4 (which
I am using Visual Studio Express 2012 RC. If a create a blank hello
Started using Visual Studio 2012 RC since yesterday, We have one WCF solution. Whenever
I'm using Visual Studio 2012 for Windows Phone 7 and this is my first
I'm using the JavaScript Grid App template in Visual Studio Express 2012 to build
I'm using Microsoft Visual Studio Express 2012 for Web. It seems that every file
I was developing winRT app using Win8 RP and visual studio express 2012. The
I'm using Visual Studio Express 2012 on the Windows 8 Release Preview and I
I'm writing a MVC4 Website using Microsoft Visual Studio express 2012 for web. Whenever
Using Visual Studio 2012, I created a new ASP.NET MVC 4 web project, 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.