Solved

why doesn't the data table display (newbie)

Posted on 2004-09-03
3
246 Views
Last Modified: 2010-04-23
In the code below DS is the Dataset. WHy doesn't the following code display a table?

        Dim stTableName As String = "Search" & NewSearchID.ToString
        Dim DT As New DataTable()
        DT.TableName = stTableName

        DS.Tables.Add(DT)

        DT.Columns.Add("A1", Type.GetType("System.String"))
        DT.Columns.Add("A2", Type.GetType("System.String"))
        DT.Columns.Add("A3", Type.GetType("System.String"))
        DT.Columns.Add("A4", Type.GetType("System.String"))
        DT.Columns.Add("A5", Type.GetType("System.String"))
        DT.Columns.Add("A6", Type.GetType("System.String"))

        Dim iIndex As Long
        Dim DR As DataRow
        For iIndex = 1 To 10
            DR = DT.NewRow
            DR("A1") = Str$(iIndex)
            DR("A2") = Str$(iIndex)
            DR("A3") = Str$(iIndex)
            DR("A4") = Str$(iIndex)
            DR("A5") = Str$(iIndex)
            DR("A6") = Str$(iIndex)

            DT.Rows.Add(DR)
        Next

        NG.SetDataBinding(DS, stTableName)

    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
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 11978132
It does on my system.  Here is the testform I used:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents NG As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.NG = New System.Windows.Forms.DataGrid
        CType(Me.NG, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(88, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'NG
        '
        Me.NG.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.NG.DataMember = ""
        Me.NG.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.NG.Location = New System.Drawing.Point(8, 40)
        Me.NG.Name = "NG"
        Me.NG.Size = New System.Drawing.Size(272, 216)
        Me.NG.TabIndex = 1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.NG)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.NG, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private DS As New DataSet
    Private NewSearchID As Integer = 1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim stTableName As String = "Search" & NewSearchID.ToString
        Dim DT As New DataTable
        DT.TableName = stTableName

        DS.Tables.Add(DT)

        DT.Columns.Add("A1", Type.GetType("System.String"))
        DT.Columns.Add("A2", Type.GetType("System.String"))
        DT.Columns.Add("A3", Type.GetType("System.String"))
        DT.Columns.Add("A4", Type.GetType("System.String"))
        DT.Columns.Add("A5", Type.GetType("System.String"))
        DT.Columns.Add("A6", Type.GetType("System.String"))

        Dim iIndex As Long
        Dim DR As DataRow
        For iIndex = 1 To 10
            DR = DT.NewRow
            DR("A1") = Str$(iIndex)
            DR("A2") = Str$(iIndex)
            DR("A3") = Str$(iIndex)
            DR("A4") = Str$(iIndex)
            DR("A5") = Str$(iIndex)
            DR("A6") = Str$(iIndex)

            DT.Rows.Add(DR)
        Next
        NG.SetDataBinding(DS, stTableName)
    End Sub

End Class
0
 

Author Comment

by:rdavis101
ID: 11978140
You're right, it does...thanks dude.

Roger
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11978147
Um...glad I could help.

=)
Idle_Mind
0

Featured Post

Industry Leaders: 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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