Solved

Simple table doesn't display (newbie)

Posted on 2004-09-03
2
297 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
2 Comments
 
LVL 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getfiles in vb.net 28 42
Visual Studio .Net 2012 and Crystal Reports 9 45
C# Single Form 8 26
Exit the loop 4 34
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now