Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy one table to another based on criteria
    text
    copied!<p>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:</p> <ol> <li>Select a record from MBRHISTDETL</li> <li>Is it BILLTYPE 09 and is BILLMOYR &lt;> 9999? If yes, continue. If not, get another record.</li> <li>Use MBRNUM from MBRHISTDETL to get LOCATION, DISTRICT, and CYCLE from LOCINFODETL.</li> <li>Does DISTRICT and CYCLE match the input parameters cbDistrict and cbCycle? If no, get another record.</li> <li>Populate datatable</li> <li>Go back to 1 unless end of file.</li> </ol> <p>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?</p> <p>Here's my code so far:</p> <pre><code>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 &lt;&gt; '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(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload