DataGrid - Dataset

P

Paul W Smith

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

[connection object creation]

Dim sSQL As String = "SELECT * FROM tPlayers"

Dim myAdapter As OleDbDataAdapter = New
OleDbDataAdapter(sSQL,myConnection)


Dim MyDataSet As New DataSet

myAdapter.Fill(MyDataSet)


GridView1.DataSource = MyDataSet

GridView1.DataBind()

myConnection.Close()

End Sub


I know the connection object is good because I use it else where, I have
edited out from the event above.

I have the require Namespaces , so it must be syntax, but I cannot for the
life of me see what the problem is.

Can anyone else?
 
S

sloan

GridView1.DataSource = MyDataSet.Tables[0];


A DataSet is a collection of DataTables.

You have to pick a Table.
 
I

IfThenElse

Never mind command object,

Are you or are you not getting a Syntax error.
Syntax errors are generated by the complier before the runtime errors.

Can you findout what you get from MyDataSet.Tables.count?
or MyDataSet.Tables[0].Rows[0].count
etc...
 
I

IfThenElse

good catch, I did not see this one.


sloan said:
GridView1.DataSource = MyDataSet.Tables[0];


A DataSet is a collection of DataTables.

You have to pick a Table.




Paul W Smith said:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

[connection object creation]

Dim sSQL As String = "SELECT * FROM tPlayers"

Dim myAdapter As OleDbDataAdapter = New
OleDbDataAdapter(sSQL,myConnection)


Dim MyDataSet As New DataSet

myAdapter.Fill(MyDataSet)


GridView1.DataSource = MyDataSet

GridView1.DataBind()

myConnection.Close()

End Sub


I know the connection object is good because I use it else where, I have
edited out from the event above.

I have the require Namespaces , so it must be syntax, but I cannot for
the life of me see what the problem is.

Can anyone else?
 
S

sloan

You can also do this as a DEBUG technique.

string x = MyDataSet.GetXml();

or (vb.net)
dim x as string = MyDataSet.GetXml()

...

Look at the x value, and make sure you have information in there.




sloan said:
GridView1.DataSource = MyDataSet.Tables[0];


A DataSet is a collection of DataTables.

You have to pick a Table.




Paul W Smith said:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

[connection object creation]

Dim sSQL As String = "SELECT * FROM tPlayers"

Dim myAdapter As OleDbDataAdapter = New
OleDbDataAdapter(sSQL,myConnection)


Dim MyDataSet As New DataSet

myAdapter.Fill(MyDataSet)


GridView1.DataSource = MyDataSet

GridView1.DataBind()

myConnection.Close()

End Sub


I know the connection object is good because I use it else where, I have
edited out from the event above.

I have the require Namespaces , so it must be syntax, but I cannot for
the life of me see what the problem is.

Can anyone else?
 
G

Guest

Paul,
If it isn't working that means your code is likely throwing an exception.
But - you don't have it wired up to catch exceptions. Wrap the whole thing
in a try / catch block and in the catch block you can output the exception's
Message and StackTrace properties to the debug window and even set a
breakpoint on the debug.WriteLine statement and mouse over the exception
object to examine it with Text Visualizer from Intellisense. That's faster
than asking questions on newsgroups and waiting around for answers!
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
 
M

Mark Rae [MVP]

GridView1.DataSource = MyDataSet.Tables[0];

A DataSet is a collection of DataTables.

Yes it is.
You have to pick a Table.

No you don't - if the DataSet has only one table, you don't need to specify
it...

GridView1.DataSource = MyDataSet
 
M

Mark Rae [MVP]

I have the require Namespaces , so it must be syntax, but I cannot for the
life of me see what the problem is.

Can anyone else?

You've forgotten the Command object...
 
P

Paul W Smith

Wow....... I fell like I am being told off by the teacher for not knowing
something.

Do you have to be an expert to use this forum or can beginners use it as
well!!!

I do appreciate your initial comments, as I have all the ones that have been
made, why you felt the need to advise me that 'knowing' what to do is faster
than asking seems strange to me.

Again thanks to everyone who took time to offer some advise - which I always
thought was the purpose of these forums.

PWS



Peter Bromberg said:
Paul,
If it isn't working that means your code is likely throwing an exception.
But - you don't have it wired up to catch exceptions. Wrap the whole thing
in a try / catch block and in the catch block you can output the
exception's
Message and StackTrace properties to the debug window and even set a
breakpoint on the debug.WriteLine statement and mouse over the exception
object to examine it with Text Visualizer from Intellisense. That's faster
than asking questions on newsgroups and waiting around for answers!
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



Paul W Smith said:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

[connection object creation]

Dim sSQL As String = "SELECT * FROM tPlayers"

Dim myAdapter As OleDbDataAdapter = New
OleDbDataAdapter(sSQL,myConnection)


Dim MyDataSet As New DataSet

myAdapter.Fill(MyDataSet)


GridView1.DataSource = MyDataSet

GridView1.DataBind()

myConnection.Close()

End Sub


I know the connection object is good because I use it else where, I have
edited out from the event above.

I have the require Namespaces , so it must be syntax, but I cannot for
the
life of me see what the problem is.

Can anyone else?
 
S

sloan

Another way to help (future readers) is to post:
if you resolved the issue, and
what the resolution was.

...




Paul W Smith said:
Wow....... I fell like I am being told off by the teacher for not knowing
something.

Do you have to be an expert to use this forum or can beginners use it as
well!!!

I do appreciate your initial comments, as I have all the ones that have
been made, why you felt the need to advise me that 'knowing' what to do is
faster than asking seems strange to me.

Again thanks to everyone who took time to offer some advise - which I
always thought was the purpose of these forums.

PWS



"Peter Bromberg [C# MVP]" <[email protected]>
wrote in message
Paul,
If it isn't working that means your code is likely throwing an exception.
But - you don't have it wired up to catch exceptions. Wrap the whole
thing
in a try / catch block and in the catch block you can output the
exception's
Message and StackTrace properties to the debug window and even set a
breakpoint on the debug.WriteLine statement and mouse over the exception
object to examine it with Text Visualizer from Intellisense. That's
faster
than asking questions on newsgroups and waiting around for answers!
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



Paul W Smith said:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

[connection object creation]

Dim sSQL As String = "SELECT * FROM tPlayers"

Dim myAdapter As OleDbDataAdapter = New
OleDbDataAdapter(sSQL,myConnection)


Dim MyDataSet As New DataSet

myAdapter.Fill(MyDataSet)


GridView1.DataSource = MyDataSet

GridView1.DataBind()

myConnection.Close()

End Sub


I know the connection object is good because I use it else where, I have
edited out from the event above.

I have the require Namespaces , so it must be syntax, but I cannot for
the
life of me see what the problem is.

Can anyone else?
 
P

PWS

Another way to help (future readers) is to post:
if you resolved the issue, and > what the resolution was.

I always like to try to help others where I can.

I have solved my problem, but I still do not understand it so perhaps
someone might assist me.

I am a little loathed to write this because it probably shows both my
inexperience and lack of knowledge, you can only get so much from
reading books, and I am not a ASP.NET professional, just a keen
amateur who codes in his spare time on small projects.

My problem which I discovered by trying to debug my code was that it
was not running. I am using Visual Studio 2005 and I noticed that
when in Source View "Client Objects and Events" was displayed, rather
than "Server Objects and Events." Unfortunately I looked in the drop
down and did not see "Server Objects and Events" so just opened a page
that did work and saved it with the new required name and amended the
code.

Thanks to everyone who tried to assist, your advice was apprecaited
and follwoing it helped me find my problem.
 
S

sloan

That's cool dude.

Live and learn with this stuff.

I'm a little unsure about what you've said, but I'll take a guess.

Look at the code of the aspx page (the html-ish type stuff, not the code
behind page).


CodeBehind="ManageUsers.aspx.vb"
Inherits="MyApplication.Presentation.Web1.ManageUsers"

When you do "copy and paste" stuff, sometimes this things get out of whack.

I'm probably way off, but thought I'd mention that one, since I was burned
by it early on.
 
S

sloan

Ahh. You got me Mark, well played.

Now I remember that code which checks the "object" datasource, and you're
right, there is a
"If type is dataset and table.count = 1 then use the first table
(table[0])."

So I was off on this one, however it is good to know that if you have a
DataSet with more than 1 table, you need to specify the specific table of
interest.




Mark Rae said:
GridView1.DataSource = MyDataSet.Tables[0];

A DataSet is a collection of DataTables.

Yes it is.
You have to pick a Table.

No you don't - if the DataSet has only one table, you don't need to
specify it...

GridView1.DataSource = MyDataSet
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top