Error Returning DataSet from function

I’m hoping someone can spot the novice mistake I’m clearly making as I test returning a dataset from a simple function. I’ve made numerous attempts at the datacolumns to datatable to dataset constructions and I still receive the dreaded “Generic error”. I’m sure it has to do with the way I’m handling the DataSet, but I’ve searched all over the info nets and now am forced to cry Uncle!
image

DataTable tbl = new DataTable();

tbl.Columns.Add("OrderNum", typeof(int));
tbl.Columns.Add("OrderRel", typeof(int));
tbl.Columns.Add("OrderLine",typeof(int));
tbl.Columns.Add("PartNum", typeof(string));
tbl.Columns.Add("ItemQty",typeof(int));
tbl.Columns.Add("JobNum", typeof(string));

var dtlrows = (from j in Db.JobProd where j.OrderNum == inOrderNum select new {j.OrderNum, j.OrderRelNum, j.OrderLine, j.PartNum, j.ProdQty, j.JobNum} );
string orderDtls = "";
if(dtlrows !=null)
{
    foreach (var dr in dtlrows) 
    {
      orderDtls += "\r\n" + dr.OrderNum + "~" + dr.OrderLine + "~" + dr.PartNum + "~" + dr.JobNum + "~" + dr.ProdQty ;
      tbl.Rows.Add(dr.OrderNum, dr.OrderRelNum, dr.OrderLine, dr.PartNum, dr.ProdQty, dr.JobNum);
    }
}
output = orderDtls;
dsOutput.Tables.Add("tbl");

The code editor is happy…

image

But the Postman is not…

I know that data is present as the string value returns data when I comment out the DataSet stuff. Oh… I’ve also tried the Tables.Add() without quotes around the table name.

You can’t add the table to the dataset as a string you need to add the table to the dataset the table object not the string “tbl”

And from the code shown at least, you haven’t initialized the dataset either.

dsOutput = new DataSet();

1 Like

Thanks Jose. I tried it both ways - as a string just because I ran out of things to try.

That was it, Kevin. I thought of very early on, but was SURE I didn’t have to initialize that output dataset because I didn’t have to do that with any other in/out variables!

Thanks a lot gents! Truly appreciated.