?
Solved

why doesn't the data table display (newbie)

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

764 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