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 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

When I run the program below on my Mac (OS/X 10.6.4), I get the
In the program below i initiliaze i to 255 Thus in Binary we have:
I have written a sample program below. class Program { static int x =
I have written a program that reads in a File object (really an XML
In below program why does the compiler generate an error for the call to
I have the below program to obtain current date and time. int main(void) {
Here is the output for the below program. value is : 2.7755575615628914E-17 Double.compare with
I have written the java code below, which executes another java program named Newsworthy_RB.
I have a C program below written on UNIX. I am getting segmentation fault.
In the program below, the result is that 0.0 is considered less than Double.MIN_VALUE

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.