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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:50:51+00:00 2026-05-24T03:50:51+00:00

In my program below, I’m writing every record I select from MBRHISTDETL to a

  • 0

In my program below, I’m writing every record I select from MBRHISTDETL to a datatable. However, whenever a record is read from the MBRHISTDTL file, I’d like to perform more actions before writing it to the datatable. The way the program is written, though, it will write the whole resultset to the datatable when I only want particular records being written. How can I change this? What I’d like to do is this:

  1. Select a record from MBRHISTDETL
  2. Is it BILLTYPE 09 and is BILLMOYR <> 9999? If yes, continue. If not, get another record.
  3. Use MBRNUM from MBRHISTDETL to get LOCATION, DISTRICT, and CYCLE from LOCINFODETL.
  4. Does DISTRICT and CYCLE match the input parameters cbDistrict and cbCycle? If no, get another record.
  5. Populate datatable
  6. Go back to 1 unless end of file.

As my code is written right now, I can only complete steps 1 through 3 because I haven’t figured out a way to grab a record from MBRHISTDETL and use that info to select another record from LOCINDODETL to verify the record I have is correct before writing to the datatable. Basically, I’m trying to get information from two different database files and write the information to a datatable. Am I going about this the right way?

Here’s my code so far:

private void btnGo_Click(object sender, EventArgs e)
    {
        //get parameters
        string cycle = cbCycle.Text;
        string district = cbDistrict.Text;

        //create a connection to the database
        OdbcConnection DbConnection = new OdbcConnection("DSN=UPN2;uid=xxxx;pwd=xxxx");
        DbConnection.Open();

        //create a command to extract the required data and
        //assign it to the connection string
        OdbcCommand DbCommand = DbConnection.CreateCommand();
        DbCommand.CommandText = "SELECT * FROM CAV_MBRHISTDETL WHERE BILLTYPE = '09' " +
            "AND BILLMOYR <> '9999'";

        //Create a DataAdapter to run the command and fill the datatable
        OdbcDataAdapter da = new OdbcDataAdapter();
        da.SelectCommand = DbCommand;
        DataTable dt = new DataTable();

        //Put results into datatable.
        da.Fill(dt);


        tbOutput.Text = PrintDataTable(dt);

        DbCommand.Dispose();
        DbConnection.Close();

    }
  • 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-24T03:50:52+00:00Added an answer on May 24, 2026 at 3:50 am

    If the tables are in the same database, you likely (depending on the database backend and configuration) could use an inner join to get all your data in a single query. For instance:

    DbCommand.CommandText = 
     @"SELECT HIST.Field1, HIST.Field2, LOCINFO.Field3 FROM CAV_MBRHISTDEL AS HIST
       INNER JOIN LOCINFODETL AS LOCINFO ON HIST.MBRNUM = LOCINFO.MBRNUM 
       WHERE LOCINFO.CYCLE = @CYCLE AND
             LOCINFO.DISTRICT = @DISTRICT AND
             HIST.BILLTYPE = '09' AND
             HIST.BOLLMOYR <> '9999'";
    
    DbCommand.Parameters.AddWithValue("@CYCLE", cycle);
    DbCommand.Parameters.AddWithValue("@DISTRICT", district);
    

    This takes care of your steps 1, 2, 3, 4, and 6, which all relate to selecting the data you need. Step 5 simply requires executing the command to fill a data table. (Note: replace Field1, Field2, etc. with the actual fields you need for the your data table, and LOCINFO.MBRNUM with LOCINFO.(whichever field in LOCINFODETL corresponds to MBRNUM).)

    If the SQL query syntax is unclear, you may want to reference inner joins, parameterized queries, and table aliasing for more on the syntax.

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

Sidebar

Related Questions

The program below should read in a bunch of integers from a file and
I wrote the program below in order to read every line of the file
The c++ program below fails to read the file. I know using cstdio is
Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
The short program below is intended to iterate over argv passed from the command
Consider the program below. It has been simplified from a complex case. It fails
I have a program below that tries to take input from the user and
my program below is a simple windows form that searches for a file in
My little program below shall take 5 numbers from the user, store them into
From the program below or here , why does the last call to System.out.println(i)

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.