By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Populating a DataGrid

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
What is the error you are getting?

"Bob Hollness" <bo*@blockbuster.com> wrote in message
news:ew***************@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.

Nov 19 '05 #2

P: n/a
After
TextGrid.DataSource = TextDataTable

One more line code:

TextGrid.DataBind()

Hope it helps.

Elton Wang
el********@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 tableusing the .NET connector (ByteFX). But for the life of me, I just cannotwork it out. Can someone tell me what I am doing wrong? What I want is toclick a button and the contents of the table from the DB appears in theDataGrid on my ASP page.

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

Dim ConnStr As String

ConnStr = "server=localhost; user
id=test;password=password;database=documents;pool ing=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.
.

Nov 19 '05 #3

P: n/a
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.

Nov 19 '05 #4

P: n/a
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" <bo*@blockbuster.com> wrote in message
news:ew***************@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.

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.