Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Usinh table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Net 2+

    i seem to be missing something (mostly any displayed data) but the articles i've been reading don't indicate a problem.

    the code

    Using connection As New SqlConnection("CONNECT STRING TO SQL SERVER")

    Using command As New SqlCommand(strSQL, connection)

    connection.Open()

    Using reader As SqlDataReader = command.ExecuteReader()

    Dim table As New DataTable()
    Dim myDG As New DataGrid

    table.Load(reader)
    myDG.DataSource = table

    End Using

    End Using

    End Using

    Doesn't display. When i copy/paste the SQL in question to a query in SQL Server, data is returned. According to one article, there isn't much to think about. With this scenario:

    // Display data in GridView

    dataGridView1.DataSource = table; <-- a one-line that displays that thar data!

    so, no fill or rs.MoveFirst or stuff like that. just point to the datasource, boom yer' done. Or, in this case, not...

    any ideas?

    TIA

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Usinh table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Ne

    Well the obvious thing is to ask if this is actually the code you tried, because "CONNECT STRING TO SQL SERVER certainly isn't a valid connect string. Your connection is the most likely culprit because the rest of the code looks OK.
    Charlotte

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Usinh table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Ne

    the connect string i am actually using is copy/pasted from a VS project, where i can display data from the db (but not using this select method). If you think the code looks otherwise functional that at least helps me know i didn't miss something on the use of table.Load.

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Usin table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Ne

    <font color=red>PROBLEM SOLVED. Use of code-behind with appropriate onload events did it.</font color=red>

    Another thing I am probably doing wrong is, the code previously posted that defines and loads a DataTable doesn't actually contain a control to display the data. i am a little confused on how best to do this, however. should i set the code for loading data to the DataTable somewhere other than the .aspx page? I am having no luck on declaring a datagrid and setting the source of the control to the ASP code above the datagrid control. also, is it better to use a DataSet as opposed to a DataTable? my reading on this point appears to indicate that DataTable is a little like getrows in that the data is put into memory and the connection is shut down, as opposed to DataSet where the connection remains open until explicitly shut.

    But I am still rather new with .NET so I am not willing to risk much on my being right.

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Usin table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Ne

    I'm glad you figured it out. Never be afraid of asking questions here - everyone is ever so helpful!

    Good luck with your project!
    Carpy Diem, it&#39;s .

  6. #6
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Usin table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Ne

    thanks - it's coming along. i am learning how to think in .NET (code behind and event handling), so it's a process.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Usin table.Load from DataTable not working (ASP.NET, VS 2008 Pro, .Ne

    What you use largely depends on how you intend to use it and manipulate it.. I normally use a DataView, especially in grids, because it provides for sorting, filtering, finding, etc., in addition to basic data handling.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •