[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

why doesn't the data table display (newbie)

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
rdavis101
Asked:
rdavis101
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
rdavis101Author Commented:
You're right, it does...thanks dude.

Roger
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Um...glad I could help.

=)
Idle_Mind
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now