?
Solved

Simple table doesn't display (newbie)

Posted on 2004-09-03
2
Medium Priority
?
301 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 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