Solved

Simple table doesn't display (newbie)

Posted on 2004-09-03
2
299 Views
Last Modified: 2010-04-23
A datagrid and a button exist on a form. When I click the button, the code below should create a new dataset, create a new table, create a single new column, then add 10 rows, then bind the datasource to the Datagrid for display.

My message box tells me that there are 10 rows, but the table doesn't display.

Why?
------------

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DS As New DataSet()
        Dim DT As New DataTable()
        Dim DR As DataRow

        DT.TableName = "Yo"
        DS.Tables.Add("Yo")

        DT.Columns.Add("Raj")

        Dim iIndex As Long
        For iIndex = 1 To 10
            DR = DT.NewRow
            DR("Raj") = Str$(iIndex)
            DT.Rows.Add(DR)
        Next

        MessageBox.Show(DT.Rows.Count.ToString)

        DataGrid1.SetDataBinding(DS, "Yo")

    End Sub
0
Comment
Question by:rdavis101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 11977695
The problem was you never actually added your DataTable to your DataSet.  Instead, you created a new table called "Yo" and then added all the records to your local DataTable:    

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DS As New DataSet
        Dim DT As New DataTable
        Dim DR As DataRow

        DT.TableName = "Yo"
        ' DS.Tables.Add("Yo") ' <---------- This created a new, different table in DS called "Yo"
        DS.Tables.Add(DT) ' <---------- Add the table you are working with to the DataSet

        DT.Columns.Add("Raj")

        Dim iIndex As Long
        For iIndex = 1 To 10
            DR = DT.NewRow
            DR("Raj") = Str$(iIndex)
            DT.Rows.Add(DR)
        Next

        MessageBox.Show(DT.Rows.Count.ToString)

        DataGrid1.SetDataBinding(DS, "Yo")

    End Sub

Regards,

{pseudocode} / {Time} ± ¼*ƒ(Me.Thoughts÷3)^² = Idle »(°_°)« Mind
0
 

Author Comment

by:rdavis101
ID: 11977753
Thanks, dude.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question