Populating a DataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Hollness

    Populating a DataGrid

    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=localho st; user
    id=test;passwor d=password;data base=documents; pooling=false"

    Try

    Dim TextConn As New MySqlConnection (ConnStr)
    Dim TableAdaptor As New MySqlDataAdapte r
    'Dim CommBuild As New MySqlCommandBui lder
    Dim TextDataTable As New DataTable

    TextConn.Open()

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

    'CommBuild = New MySqlCommandBui lder(TableAdapt or)

    TableAdaptor.Fi ll(TextDataTabl e)

    TextGrid.DataSo urce = TextDataTable

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

    Catch ex As Exception

    BodyBox.Text = ex.Message

    End Try


    Thanks.

    --

    Bob

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


  • Tarren

    #2
    Re: Populating a DataGrid

    What is the error you are getting?

    "Bob Hollness" <bob@blockbuste r.com> wrote in message
    news:ewNHEyM%23 EHA.220@TK2MSFT NGP09.phx.gbl.. .[color=blue]
    > 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=localho st; user
    > id=test;passwor d=password;data base=documents; pooling=false"
    >
    > Try
    >
    > Dim TextConn As New MySqlConnection (ConnStr)
    > Dim TableAdaptor As New MySqlDataAdapte r
    > 'Dim CommBuild As New MySqlCommandBui lder
    > Dim TextDataTable As New DataTable
    >
    > TextConn.Open()
    >
    > TableAdaptor = New MySqlDataAdapte r("SELECT * FROM daniel",
    > TextConn)
    >
    > 'CommBuild = New MySqlCommandBui lder(TableAdapt or)
    >
    > TableAdaptor.Fi ll(TextDataTabl e)
    >
    > TextGrid.DataSo urce = TextDataTable
    >
    > IDBox.Text = TextGrid.Items. Count
    > 'TitleBox.Text = TextDataTable.C olumns.Count
    > BodyBox.Text = "Success"
    >
    > Catch ex As Exception
    >
    > BodyBox.Text = ex.Message
    >
    > End Try
    >
    >
    > Thanks.
    >
    > --
    >
    > Bob
    >
    > --------------------------------------
    > I'll have a B please Bob.
    >
    >[/color]


    Comment

    • Elton Wang

      #3
      Populating a DataGrid

      After
      TextGrid.DataSo urce = TextDataTable

      One more line code:

      TextGrid.DataBi nd()

      Hope it helps.

      Elton Wang
      elton_wang@hotm ail.com

      [color=blue]
      >-----Original Message-----
      >Hi all. I hope this is the right group
      >
      >I am trying to populate a datagrid on an ASP.NET page[/color]
      from a MySQL table[color=blue]
      >using the .NET connector (ByteFX). But for the life of[/color]
      me, I just cannot[color=blue]
      >work it out. Can someone tell me what I am doing wrong?[/color]
      What I want is to[color=blue]
      >click a button and the contents of the table from the DB[/color]
      appears in the[color=blue]
      >DataGrid on my ASP page.
      >
      >I tried to follow an example on the web and I just got[/color]
      lost. I have posted[color=blue]
      >my code below.
      >
      > Dim ConnStr As String
      >
      > ConnStr = "server=localho st; user
      >id=test;passwo rd=password;dat abase=documents ;pooling=false[/color]
      "[color=blue]
      >
      > Try
      >
      > Dim TextConn As New MySqlConnection (ConnStr)
      > Dim TableAdaptor As New MySqlDataAdapte r
      > 'Dim CommBuild As New MySqlCommandBui lder
      > Dim TextDataTable As New DataTable
      >
      > TextConn.Open()
      >
      > TableAdaptor = New MySqlDataAdapte r("SELECT *[/color]
      FROM daniel",[color=blue]
      >TextConn)
      >
      > 'CommBuild = New MySqlCommandBui lder[/color]
      (TableAdaptor)[color=blue]
      >
      > TableAdaptor.Fi ll(TextDataTabl e)
      >
      > TextGrid.DataSo urce = TextDataTable
      >
      > IDBox.Text = TextGrid.Items. Count
      > 'TitleBox.Text = TextDataTable.C olumns.Count
      > BodyBox.Text = "Success"
      >
      > Catch ex As Exception
      >
      > BodyBox.Text = ex.Message
      >
      > End Try
      >
      >
      >Thanks.
      >
      >--
      >
      >Bob
      >
      >--------------------------------------
      >I'll have a B please Bob.
      >
      >
      >.
      >[/color]

      Comment

      • sara

        #4
        RE: Populating a DataGrid

        Hi Bob
        try this
        say that the table on the db is t1
        dim con as new sqlconnection(c onstr)
        dim adapter as new sqladapter("sel ect * from t1",con)
        dim ds as new dataset()
        adapter.fill(ds ,"mytable")
        yourGrid.dataso urce(ds)
        yourgrid.datame mber("mytable")
        yourgrid.databi nd()
        this will work
        do not open connection with dataadpter



        "Bob Hollness" wrote:
        [color=blue]
        > 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=localho st; user
        > id=test;passwor d=password;data base=documents; pooling=false"
        >
        > Try
        >
        > Dim TextConn As New MySqlConnection (ConnStr)
        > Dim TableAdaptor As New MySqlDataAdapte r
        > 'Dim CommBuild As New MySqlCommandBui lder
        > Dim TextDataTable As New DataTable
        >
        > TextConn.Open()
        >
        > TableAdaptor = New MySqlDataAdapte r("SELECT * FROM daniel",
        > TextConn)
        >
        > 'CommBuild = New MySqlCommandBui lder(TableAdapt or)
        >
        > TableAdaptor.Fi ll(TextDataTabl e)
        >
        > TextGrid.DataSo urce = TextDataTable
        >
        > IDBox.Text = TextGrid.Items. Count
        > 'TitleBox.Text = TextDataTable.C olumns.Count
        > BodyBox.Text = "Success"
        >
        > Catch ex As Exception
        >
        > BodyBox.Text = ex.Message
        >
        > End Try
        >
        >
        > Thanks.
        >
        > --
        >
        > Bob
        >
        > --------------------------------------
        > I'll have a B please Bob.
        >
        >
        >[/color]

        Comment

        • Bob Hollness

          #5
          Re: Populating a DataGrid

          Don't worry, I solved it.

          I changed "TextGrid.DataS ource = TextDataTable" to "TextGrid.DataS ource =
          TextDataTable.D efaultView"

          --

          Bob

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

          "Bob Hollness" <bob@blockbuste r.com> wrote in message
          news:ewNHEyM%23 EHA.220@TK2MSFT NGP09.phx.gbl.. .[color=blue]
          > 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=localho st; user
          > id=test;passwor d=password;data base=documents; pooling=false"
          >
          > Try
          >
          > Dim TextConn As New MySqlConnection (ConnStr)
          > Dim TableAdaptor As New MySqlDataAdapte r
          > 'Dim CommBuild As New MySqlCommandBui lder
          > Dim TextDataTable As New DataTable
          >
          > TextConn.Open()
          >
          > TableAdaptor = New MySqlDataAdapte r("SELECT * FROM daniel",
          > TextConn)
          >
          > 'CommBuild = New MySqlCommandBui lder(TableAdapt or)
          >
          > TableAdaptor.Fi ll(TextDataTabl e)
          >
          > TextGrid.DataSo urce = TextDataTable
          >
          > IDBox.Text = TextGrid.Items. Count
          > 'TitleBox.Text = TextDataTable.C olumns.Count
          > BodyBox.Text = "Success"
          >
          > Catch ex As Exception
          >
          > BodyBox.Text = ex.Message
          >
          > End Try
          >
          >
          > Thanks.
          >
          > --
          >
          > Bob
          >
          > --------------------------------------
          > I'll have a B please Bob.
          >
          >[/color]


          Comment

          Working...