locked
Data table in asp.net RRS feed

  • Question

  • User1480781148 posted

    Hi, 

    Is feasible performance point of view to create dynamically data table in asp.net web, furthermore what, an is difference between

    creating data table with session variable "Session("myDatatable") = myDt  " as in following example I created ,  and without session variable , and which is best way.


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
    If Me.IsPostBack = False Then
    myDt = New DataTable()
    myDt = CreateDataTable()
    Session("myDatatable") = myDt

    Me.GridView1.DataSource = (CType(Session("myDatatable"), DataTable)).DefaultView
    Me.GridView1.DataBind()
    End If
    End Sub


    Private Function CreateDataTable() As DataTable
    Dim myDataTable As DataTable = New DataTable()

    Dim myDataColumn As DataColumn

    myDataColumn = New DataColumn()
    myDataColumn.DataType = Type.GetType("System.String")
    myDataColumn.ColumnName = "id"
    myDataTable.Columns.Add(myDataColumn)

    myDataColumn = New DataColumn()
    myDataColumn.DataType = Type.GetType("System.String")
    myDataColumn.ColumnName = "username"
    myDataTable.Columns.Add(myDataColumn)

    myDataColumn = New DataColumn()
    myDataColumn.DataType = Type.GetType("System.String")
    myDataColumn.ColumnName = "firstname"
    myDataTable.Columns.Add(myDataColumn)

    myDataColumn = New DataColumn()
    myDataColumn.DataType = Type.GetType("System.String")
    myDataColumn.ColumnName = "lastname"
    myDataTable.Columns.Add(myDataColumn)

    Return myDataTable
    End Function

    Saturday, October 11, 2014 7:28 AM

Answers

  • User-821857111 posted

    Passing data to a procedure in that fashion is fine from a performance point of view.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 14, 2014 12:11 PM

All replies

  • User-1716253493 posted
    The difference is the datatable
    keep in session variable you can
    access it from other pages. If you only want use it in the page and don't need to keep it in memory, Don't use session.
    Saturday, October 11, 2014 7:44 AM
  • User1480781148 posted

    ok, I want to inquire, data tables not decrease web application performance specially over internet when passing whole data table to a database procedure.

    thank you.

    Saturday, October 11, 2014 5:31 PM
  • User-821857111 posted

    DataTables are just a way of moving data around an application in a structured format. The recommended way to manage data these days is in the form of business objects. That gives you strong typing and compile time checking. As far as performance is concerned, a datatable of e.g. customers will require a bit more in terms of resources than an equivalent collection of Customer objects. That's because the datatable object also includes a bunch of schema information. However, it is unlikely that users of your application will notice the difference.

    when passing whole data table to a database procedure.

    I don't understand what you mean by this. You can't pass a datatable to a database procedure. Database systems don't know anything about .NET datatables and can't do anything with them.

    Tuesday, October 14, 2014 2:23 AM
  • User1480781148 posted

    for example we developed asp.net page which contain multiple records and now we want to save/insert into our database, it is not a good practices to call/execute sqlcommand for each record, in such scenarios, we will create database stored procedure, having user define data type as data table and pass it to procedure. if you want I can provide you sample code.

    thank you.

    regards,

    asad

    Tuesday, October 14, 2014 10:52 AM
  • User-821857111 posted

    Passing data to a procedure in that fashion is fine from a performance point of view.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 14, 2014 12:11 PM