locked
Transfering SQL table over TCP RRS feed

  • Question

  • Hello,

    I need to trandfer a SQL table from the server to a client over TCP connection. 

    I know it is probably possible to write the whole content of the table as a very long string, send it, and then split it in the client section, but I wanted to know if it's possible to do it in a better way?

    Also, what is the best way to display the table in the form? A DataGridView?

    Tuesday, March 27, 2018 5:32 PM

Answers

  • but I wanted to know if it's possible to do it in a better way?

    You don't send a datatable. You send a DTO, a XML serializable DTO and deserialize it back to a DTO.

    https://en.wikipedia.org/wiki/Data_transfer_object

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    Also, what is the best way to display the table in the form? A DataGridView?

    You can bind a List<T> a collection of DTO(s) to the grid.

    • Marked as answer by Roy Jiny Friday, March 30, 2018 12:02 PM
    Tuesday, March 27, 2018 8:11 PM

All replies

  • Why must you use TCP? Just do a query of the table. Use "*" for the fields if you want to.

    If you are using Windows Forms then you need to use the Windows Forms forum.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, March 27, 2018 5:55 PM
  • but I wanted to know if it's possible to do it in a better way?

    You don't send a datatable. You send a DTO, a XML serializable DTO and deserialize it back to a DTO.

    https://en.wikipedia.org/wiki/Data_transfer_object

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    Also, what is the best way to display the table in the form? A DataGridView?

    You can bind a List<T> a collection of DTO(s) to the grid.

    • Marked as answer by Roy Jiny Friday, March 30, 2018 12:02 PM
    Tuesday, March 27, 2018 8:11 PM
  • First of all, the general best way does not exist, otherwise there was only one way.

    The easiest way is to use a SQLDataAdapter, use a Fill and connect to your SQL server using Server security. 

     That are about 5 rows of C# code. 

    Success
    Cor

    Tuesday, March 27, 2018 8:46 PM
  • You don't need to transfer the whole table to display it in a DataGridView, just use paging and query what you need to display.

    https://www.codeproject.com/articles/211551/a-simple-way-for-paging-in-datagridview-in-winform


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, March 27, 2018 9:36 PM