Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataGrid - Dataset

0 views
Skip to first unread message

Paul W Smith

unread,
Oct 11, 2007, 3:40:16 PM10/11/07
to
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?


sloan

unread,
Oct 11, 2007, 3:51:06 PM10/11/07
to

GridView1.DataSource = MyDataSet.Tables[0];


A DataSet is a collection of DataTables.

You have to pick a Table.


"Paul W Smith" <p...@NOSPAM.twelve.me.uk> wrote in message
news:%23vRvD8D...@TK2MSFTNGP03.phx.gbl...

IfThenElse

unread,
Oct 11, 2007, 3:51:49 PM10/11/07
to
Where is the command object.

"Paul W Smith" <p...@NOSPAM.twelve.me.uk> wrote in message
news:%23vRvD8D...@TK2MSFTNGP03.phx.gbl...

IfThenElse

unread,
Oct 11, 2007, 3:56:30 PM10/11/07
to
good catch, I did not see this one.


"sloan" <sl...@ipass.net> wrote in message
news:eJVaQAED...@TK2MSFTNGP06.phx.gbl...

IfThenElse

unread,
Oct 11, 2007, 3:55:49 PM10/11/07
to
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...


"Paul W Smith" <p...@NOSPAM.twelve.me.uk> wrote in message
news:%23vRvD8D...@TK2MSFTNGP03.phx.gbl...

sloan

unread,
Oct 11, 2007, 3:57:12 PM10/11/07
to

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" <sl...@ipass.net> wrote in message
news:eJVaQAED...@TK2MSFTNGP06.phx.gbl...
>
>

Peter Bromberg [C# MVP]

unread,
Oct 11, 2007, 3:58:02 PM10/11/07
to
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

Mark Rae [MVP]

unread,
Oct 11, 2007, 4:00:46 PM10/11/07
to
"sloan" <sl...@ipass.net> wrote in message
news:eJVaQAED...@TK2MSFTNGP06.phx.gbl...

> 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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mark Rae [MVP]

unread,
Oct 11, 2007, 4:03:02 PM10/11/07
to
"IfThenElse" <sql_ag...@hotmail.com> wrote in message
news:O2vtSDED...@TK2MSFTNGP02.phx.gbl...

>> A DataSet is a collection of DataTables.
>>
>> You have to pick a Table.

> good catch, I did not see this one.

Makes no difference if the DataSet has only one Table...

Mark Rae [MVP]

unread,
Oct 11, 2007, 4:01:49 PM10/11/07
to
"Paul W Smith" <p...@NOSPAM.twelve.me.uk> wrote in message
news:%23vRvD8D...@TK2MSFTNGP03.phx.gbl...

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

Paul W Smith

unread,
Oct 11, 2007, 5:32:04 PM10/11/07
to
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]" <pbro...@yahoo.yohohhoandabottleofrum.com> wrote
in message news:6C753DEE-22CC-4EF0...@microsoft.com...

sloan

unread,
Oct 11, 2007, 6:26:56 PM10/11/07
to
Another way to help (future readers) is to post:
if you resolved the issue, and
what the resolution was.

..


"Paul W Smith" <p...@NOSPAM.twelve.me.uk> wrote in message

news:%23jtst4E...@TK2MSFTNGP02.phx.gbl...

PWS

unread,
Oct 12, 2007, 4:45:27 AM10/12/07
to

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

sloan

unread,
Oct 12, 2007, 10:44:24 AM10/12/07
to
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.


"PWS" <p...@twelve.me.uk> wrote in message
news:1192178727.2...@y27g2000pre.googlegroups.com...

sloan

unread,
Oct 12, 2007, 10:49:07 AM10/12/07
to

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 [MVP]" <ma...@markNOSPAMrae.net> wrote in message
news:OyIMlFED...@TK2MSFTNGP02.phx.gbl...

0 new messages