Populating a DataGrid

B

Bob Hollness

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.
 
B

Bob Hollness

Don't worry, I solved it.

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

Elton Wang

After
TextGrid.DataSource = TextDataTable

One more line code:

TextGrid.DataBind()

Hope it helps.

Elton Wang
(e-mail address removed)
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top