locked
how to bind 2 tables to Gridview in order to use better column headings RRS feed

  • Question

  • User-359936451 posted

    I have what is probably a common issue but just can't for the life of me think of a good way to do this.

    The requirement is for the web site to read in an ftp file. No problem. The file is a CSV with first row header, that matches up with a table, where the CSV contains all or some sub set of the header values. The remaining CSV rows correspond to the header rows within said CSV. So inserting these records to the table is not expected to be an issue.

    The issue is that the header rows are cryptic, A45D34, A45D35, A45D36, etc. (hundreds of columns). There is a corresponding CSV file that lists all of the column headings along with the corresponding display text to be used whenever a query is written against the table to display the data.

    I am wondering if there is someway to take advantage of the SQLDATASOURCE and query both tables, one with the data and the other with the display text and bind it to, for example, a Gridview, or other display control within a web form .aspx page.

    Any tutorials, examples, links, suggestions, or ideas would be greatly appreciated.

    Tuesday, October 28, 2014 4:00 PM

All replies

  • User1918509225 posted

    Hi march11,

    Based on my understanding ,you can merge the two data table  like below:

    dt1.Merge(dt2);

    More details ,please refer to the link below:
    http://msdn.microsoft.com/en-us/library/wtk78t63(v=vs.110).aspx

    Then bind the datatable to your gridview.

    Best Regards,

    Kevin Shen.

    Wednesday, October 29, 2014 5:38 AM
  • User-359936451 posted

    Very interesting approach but I still need to store the data in a SQL db. I would need to figure out what is new about one of the tables in the merge process and then build a SQL query to either Alter or Create a new table to store the records.

    I will investigate this option, thank you. I not sure it will directly help solve my requirement but it offers some flexibility in handling the sub set of data from the CSV.

    Wednesday, October 29, 2014 8:07 AM
  • User1918509225 posted

    Hi march11,

    If you want to save the new merge table ,you can simply create query to store it in database.

    Best Regards,

    Kevin Shen.

    Wednesday, October 29, 2014 10:15 PM
  • User-359936451 posted

    How would I go about typing each of the parameters if the table has not yet been defined?

    Thursday, October 30, 2014 12:04 PM
  • User1918509225 posted

    Hi march11,

    If you haven't define the table ,you can get the table column names from your data table .

    Then create sql query based on the column names .then use ado.net to create table and insert data for your table.

    Best Regards,

    Kevin Shen.

    Thursday, November 6, 2014 1:39 AM