Solved

why doesn't the data table display (newbie)

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

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 85

Expert Comment

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

=)
Idle_Mind
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

20 Experts available now in Live!

Get 1:1 Help Now