Hannington Mambo Hannington Mambo - 1 month ago 19
Vb.net Question

Get DataTable from aspx using VB 2010

I am creating a VB 2010 desktop application. I use the lines below to get a string response from an aspx page that I use to collect online data for the application.

Dim response As Byte() = myWebClient.UploadValues(myWeb & "/Default.aspx", "POST", nmv)
dim str as string = Replace(System.Text.Encoding.ASCII.GetString(response), "<(.|\n)*?>", "")
System.Text.Encoding.ASCII.GetString(response)


'nmv' is a defined NameValueCollection variable

Now I need to get this data back from the aspx page as either as nmv or a datatable. Is that possible? How could I go about doing it? I am thinking the key is in the System.'Array'... or something but I can't figure it out and I don't get any search results on the web.

Getting the data back as a string array is good for me, getting it nmv is even better; but getting it back as a DataTable would be perfect! I am able to deal with the aspx page giving back the data in any format, I just need the vb app to know how to collect it.

Thank you

Answer Source

Maybe easiest way would be to use *.ashx Http Handler (generic handler) and save DataTable to XML, something like this :

Server:

  public class Handler1 : IHttpHandler
  {
    public void ProcessRequest(HttpContext context)
    {
      /// if needed request data is in context.Request
      DataTable tbl = GetDataTable();
      /// table must have name, if not WriteXml will fail
      tbl.TableName = "TableName";
      tbl.WriteXml(context.Response.OutputStream);
    }

    public bool IsReusable
    {
      get
      {
        return false;
      }
    }

Then on client you should use ReadXml DataTable method to populate DataTable on client.