So I’ve been working on this most of the day and have been able to get pretty far using examples I’ve found.
Using @josecgomez example for how to call a query from code here, I’ve been able to run a query, and bind it to a grid. I won’t need the grid for production, I just used it for testing/learning.
Using this example from the link below, I’ve been able to loop through the rows and columns to put the whole grid into a single string.
So this is working, but I need better control over the columns. There’s good and bad to be able to read the BAQ even after it’s changed, (like the column order), but in this case the template needs to stay the same so I want to explicitly call the columns by column name rather than loop through them dynamically.
I don’t think I’m too far off, but now I need to more precisely call specific columns from my DataTable to be able to build up the string that will be sent out as a CSV to present to bartender. I’m trying to do it like this thread:
But, I’m not dealing with a grid, I have the dynamic query adapter results I am trying to use, and I’m getting confused on how I’m supposed to that DataTable. (DataTables are new to me so I’m trying to learn how to use them)
Here is the code that I have so far. The Message box is just for debugging purposes and will be removed once it’s working.
private void TruckPackButton_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
DynamicQueryAdapter dalps = new DynamicQueryAdapter(oTrans);
dalps.BOConnect();
QueryExecutionDataSet qeds = dalps.GetQueryExecutionParametersByID("PackingListPrintingDQA");
qeds.ExecutionParameter.Clear();
qeds.ExecutionParameter.AddExecutionParameterRow("JobNum",TruckJobNum.Text,"nvarchar", false, Guid.NewGuid(),"A");
qeds.ExecutionParameter.AddExecutionParameterRow("LiftNum",TruckNum.Text,"int", false, Guid.NewGuid(),"A");
dalps.ExecuteByID("PackingListPrintingDQA",qeds);
DataTable dt = dalps.QueryResults.Tables["Results"];
//udMyGrid.DataSource = dalps.QueryResults.Tables["Results"];
if (dalps.QueryResults.Tables["Results"].Rows.Count >0)
{
System.Text.StringBuilder b = new System.Text.StringBuilder();
//this is the header that I need for my bartender file
b.Append("CustName,OrderNum,JobNum,CustPoNum,TruckNum,TruckTrackingNum,TruckContainerNum,TruckSealNum,LiftNum,LiftWeight,AddedToTruckByEmpID_c,PartNum,Amount,UOM,TruckID,ShipDate,PartDescription,LiftPartComment,LiftComment,TruckComment,ShippingCompany,PrintingEmpID,CopyQty");
foreach (System.Data.DataRow r in dalps.QueryResults.Tables["Results"].Rows)
{
b.Append(Environment.NewLine);
//I need to know how to call specific columns here
b.Append(How do I call a specific column here?);
}
MessageBox.Show(b.ToString());
string mycsv = b.ToString();
string[] source = {""};
source[0] = mycsv;
System.IO.File.WriteAllLines("\\\\FolderPathHere\\Testing.csv",source);
}