Wednesday, March 21, 2012

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=localhost; user
id=test;password=password;database=documents;pooli ng=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.What is the error you are getting?

"Bob Hollness" <bob@.blockbuster.com> wrote in message
news:ewNHEyM%23EHA.220@.TK2MSFTNGP09.phx.gbl...
> 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;pooli ng=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.
After
TextGrid.DataSource = TextDataTable

One more line code:

TextGrid.DataBind()

Hope it helps.

Elton Wang
elton_wang@.hotmail.com

>--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;pooli ng=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.
>
>.
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;pooli ng=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.
>
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" <bob@.blockbuster.com> wrote in message
news:ewNHEyM%23EHA.220@.TK2MSFTNGP09.phx.gbl...
> 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;pooli ng=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.

0 comments:

Post a Comment