Populating a DataGrid

Discussion in 'ASP .Net' started by Bob Hollness, Jan 12, 2005.

  1. Bob Hollness

    Bob Hollness Guest

    Hi all. I hope this is the right group

    I am trying to populate a datagrid on an ASP.NET page from a MySQL table
    using the .NET connector (ByteFX). But for the life of me, I just cannot
    work it out. Can someone tell me what I am doing wrong? What I want is to
    click a button and the contents of the table from the DB appears in the
    DataGrid on my ASP page.

    I tried to follow an example on the web and I just got lost. I have posted
    my code below.

    Dim ConnStr As String

    ConnStr = "server=localhost; user
    id=test;password=password;database=documents;pooling=false"

    Try

    Dim TextConn As New MySqlConnection(ConnStr)
    Dim TableAdaptor As New MySqlDataAdapter
    'Dim CommBuild As New MySqlCommandBuilder
    Dim TextDataTable As New DataTable

    TextConn.Open()

    TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
    TextConn)

    'CommBuild = New MySqlCommandBuilder(TableAdaptor)

    TableAdaptor.Fill(TextDataTable)

    TextGrid.DataSource = TextDataTable

    IDBox.Text = TextGrid.Items.Count
    'TitleBox.Text = TextDataTable.Columns.Count
    BodyBox.Text = "Success"

    Catch ex As Exception

    BodyBox.Text = ex.Message

    End Try


    Thanks.

    --

    Bob

    --------------------------------------
    I'll have a B please Bob.
    Bob Hollness, Jan 12, 2005
    #1
    1. Advertising

  2. Bob Hollness

    Bob Hollness Guest

    Don't worry, I solved it.

    I changed "TextGrid.DataSource = TextDataTable" to "TextGrid.DataSource =
    TextDataTable.DefaultView"

    --

    Bob

    --------------------------------------
    I'll have a B please Bob.

    "Bob Hollness" <> wrote in message
    news:ewNHEyM%...
    > Hi all. I hope this is the right group
    >
    > I am trying to populate a datagrid on an ASP.NET page from a MySQL table
    > using the .NET connector (ByteFX). But for the life of me, I just cannot
    > work it out. Can someone tell me what I am doing wrong? What I want is
    > to click a button and the contents of the table from the DB appears in the
    > DataGrid on my ASP page.
    >
    > I tried to follow an example on the web and I just got lost. I have
    > posted my code below.
    >
    > Dim ConnStr As String
    >
    > ConnStr = "server=localhost; user
    > id=test;password=password;database=documents;pooling=false"
    >
    > Try
    >
    > Dim TextConn As New MySqlConnection(ConnStr)
    > Dim TableAdaptor As New MySqlDataAdapter
    > 'Dim CommBuild As New MySqlCommandBuilder
    > Dim TextDataTable As New DataTable
    >
    > TextConn.Open()
    >
    > TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
    > TextConn)
    >
    > 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
    >
    > TableAdaptor.Fill(TextDataTable)
    >
    > TextGrid.DataSource = TextDataTable
    >
    > IDBox.Text = TextGrid.Items.Count
    > 'TitleBox.Text = TextDataTable.Columns.Count
    > BodyBox.Text = "Success"
    >
    > Catch ex As Exception
    >
    > BodyBox.Text = ex.Message
    >
    > End Try
    >
    >
    > Thanks.
    >
    > --
    >
    > Bob
    >
    > --------------------------------------
    > I'll have a B please Bob.
    >
    >
    Bob Hollness, Jan 12, 2005
    #2
    1. Advertising

  3. Bob Hollness

    Tarren Guest

    What is the error you are getting?

    "Bob Hollness" <> wrote in message
    news:ewNHEyM%...
    > Hi all. I hope this is the right group
    >
    > I am trying to populate a datagrid on an ASP.NET page from a MySQL table
    > using the .NET connector (ByteFX). But for the life of me, I just cannot
    > work it out. Can someone tell me what I am doing wrong? What I want is
    > to click a button and the contents of the table from the DB appears in the
    > DataGrid on my ASP page.
    >
    > I tried to follow an example on the web and I just got lost. I have
    > posted my code below.
    >
    > Dim ConnStr As String
    >
    > ConnStr = "server=localhost; user
    > id=test;password=password;database=documents;pooling=false"
    >
    > Try
    >
    > Dim TextConn As New MySqlConnection(ConnStr)
    > Dim TableAdaptor As New MySqlDataAdapter
    > 'Dim CommBuild As New MySqlCommandBuilder
    > Dim TextDataTable As New DataTable
    >
    > TextConn.Open()
    >
    > TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
    > TextConn)
    >
    > 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
    >
    > TableAdaptor.Fill(TextDataTable)
    >
    > TextGrid.DataSource = TextDataTable
    >
    > IDBox.Text = TextGrid.Items.Count
    > 'TitleBox.Text = TextDataTable.Columns.Count
    > BodyBox.Text = "Success"
    >
    > Catch ex As Exception
    >
    > BodyBox.Text = ex.Message
    >
    > End Try
    >
    >
    > Thanks.
    >
    > --
    >
    > Bob
    >
    > --------------------------------------
    > I'll have a B please Bob.
    >
    >
    Tarren, Jan 12, 2005
    #3
  4. Bob Hollness

    Elton Wang Guest

    After
    TextGrid.DataSource = TextDataTable

    One more line code:

    TextGrid.DataBind()

    Hope it helps.

    Elton Wang



    >-----Original Message-----
    >Hi all. I hope this is the right group
    >
    >I am trying to populate a datagrid on an ASP.NET page

    from a MySQL table
    >using the .NET connector (ByteFX). But for the life of

    me, I just cannot
    >work it out. Can someone tell me what I am doing wrong?

    What I want is to
    >click a button and the contents of the table from the DB

    appears in the
    >DataGrid on my ASP page.
    >
    >I tried to follow an example on the web and I just got

    lost. I have posted
    >my code below.
    >
    > Dim ConnStr As String
    >
    > ConnStr = "server=localhost; user
    >id=test;password=password;database=documents;pooling=false

    "
    >
    > Try
    >
    > Dim TextConn As New MySqlConnection(ConnStr)
    > Dim TableAdaptor As New MySqlDataAdapter
    > 'Dim CommBuild As New MySqlCommandBuilder
    > Dim TextDataTable As New DataTable
    >
    > TextConn.Open()
    >
    > TableAdaptor = New MySqlDataAdapter("SELECT *

    FROM daniel",
    >TextConn)
    >
    > 'CommBuild = New MySqlCommandBuilder

    (TableAdaptor)
    >
    > TableAdaptor.Fill(TextDataTable)
    >
    > TextGrid.DataSource = TextDataTable
    >
    > IDBox.Text = TextGrid.Items.Count
    > 'TitleBox.Text = TextDataTable.Columns.Count
    > BodyBox.Text = "Success"
    >
    > Catch ex As Exception
    >
    > BodyBox.Text = ex.Message
    >
    > End Try
    >
    >
    >Thanks.
    >
    >--
    >
    >Bob
    >
    >--------------------------------------
    >I'll have a B please Bob.
    >
    >
    >.
    >
    Elton Wang, Jan 12, 2005
    #4
  5. Hi Bob
    try this
    say that the table on the db is t1
    dim con as new sqlconnection(constr)
    dim adapter as new sqladapter("select * from t1",con)
    dim ds as new dataset()
    adapter.fill(ds,"mytable")
    yourGrid.datasource(ds)
    yourgrid.datamember("mytable")
    yourgrid.databind()
    this will work
    do not open connection with dataadpter



    "Bob Hollness" wrote:

    > Hi all. I hope this is the right group
    >
    > I am trying to populate a datagrid on an ASP.NET page from a MySQL table
    > using the .NET connector (ByteFX). But for the life of me, I just cannot
    > work it out. Can someone tell me what I am doing wrong? What I want is to
    > click a button and the contents of the table from the DB appears in the
    > DataGrid on my ASP page.
    >
    > I tried to follow an example on the web and I just got lost. I have posted
    > my code below.
    >
    > Dim ConnStr As String
    >
    > ConnStr = "server=localhost; user
    > id=test;password=password;database=documents;pooling=false"
    >
    > Try
    >
    > Dim TextConn As New MySqlConnection(ConnStr)
    > Dim TableAdaptor As New MySqlDataAdapter
    > 'Dim CommBuild As New MySqlCommandBuilder
    > Dim TextDataTable As New DataTable
    >
    > TextConn.Open()
    >
    > TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
    > TextConn)
    >
    > 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
    >
    > TableAdaptor.Fill(TextDataTable)
    >
    > TextGrid.DataSource = TextDataTable
    >
    > IDBox.Text = TextGrid.Items.Count
    > 'TitleBox.Text = TextDataTable.Columns.Count
    > BodyBox.Text = "Success"
    >
    > Catch ex As Exception
    >
    > BodyBox.Text = ex.Message
    >
    > End Try
    >
    >
    > Thanks.
    >
    > --
    >
    > Bob
    >
    > --------------------------------------
    > I'll have a B please Bob.
    >
    >
    >
    =?Utf-8?B?c2FyYQ==?=, Jan 12, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    1
    Views:
    382
  2. Paul

    Timeout on populating a datagrid

    Paul, May 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,895
    Scott Allen
    May 5, 2004
  3. =?Utf-8?B?VGltOjouLg==?=

    Datagrid Dropdown not populating

    =?Utf-8?B?VGltOjouLg==?=, Aug 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    381
  4. Prime
    Replies:
    2
    Views:
    1,640
    Prime
    Oct 1, 2004
  5. Mike P

    populating dropdown in datagrid

    Mike P, Dec 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Dec 1, 2005
Loading...

Share This Page