vb.net newbie - ado...

  • Thread starter Thread starter Tym
  • Start date Start date
T

Tym

OK - thre has to be an easy solution to this...

Migrated from VB6 to vb.net

*eventually* got to populate a datase (instead of a recordset) with
the contents of a table based on an SQL query, but...

how the heck do I naviagete?

VB6:

rsRECORDSET.move
rsRECORDSET.moveftist
rsRECORDSET.movelast
rsRECORDSET.movenext
rsRECORDSET.moveprevious


VB.Net

???


Also..........

VB6:

sCRITERIA = "CREATE TABLE X,Y,X.... etc etc)
dbDATABSE.Execute sCRITERIA,dbFailOnError


VB.NET

??????


Any ideas???


advTHANKSance
 
To reference the first row:
ds.tables("tablename").rows(0)

To reference the "id" field of the first row:
ds.tables("tablename").rows(0).item("id")

So, to move to the next row:
ds.tables("tablename").rows(1).item("id")

To iterate through all the rows:
dim r as datarow
for each r in ds.tables("tablename").rows
listbox1.items.add(r.item("id"))
next

You may also want to investigate currencymanagers and typed datasets.

(I didn't copy this from VS.net, so I apoligize for typos)

Mike G.
 
Tym,

First a misunderstanding from you.
A recordset is not an equivalent from a dataset.

A recordset is more an equivalent from a datatable.

A dataset can hold a lot of datatables.

Than as addition to Mike

First I set a reference to a datatable before I show you the samples
dim dt as datatable = ds.tables(0)

What means that we now can without much typing get that table
And when we than want to take a row from that than it is

dim dr as datarow
rsRECORDSET.move
dr = dt.rows(current + 1)
dr = dt.rows(current - 1)
rsRECORDSET.moveftist dt.rows(0).(myfield)

dt.rows(dt.rows.count-1)

rsRECORDSET.movenext

dr = dt.rows(current + 1)
rsRECORDSET.moveprevious

dr = dt.rows(current - 1)

I hope this helps?

Cor
 
You need to use the currency manager.
Example.

Me.BindingContext(Me.DataSet11.SomeTable.DefaultView).Position =
(Me.BindingContext(Me.DataSet11.SomeTable.DefaultView).Position + 1)
 
To reference the first row:
ds.tables("tablename").rows(0)

To reference the "id" field of the first row:
ds.tables("tablename").rows(0).item("id")

So, to move to the next row:
ds.tables("tablename").rows(1).item("id")

To iterate through all the rows:
dim r as datarow
for each r in ds.tables("tablename").rows
listbox1.items.add(r.item("id"))
next

You may also want to investigate currencymanagers and typed datasets.

(I didn't copy this from VS.net, so I apoligize for typos)

Mike G.

Thanks - *starting* to make some sense!!
 
Tym,

First a misunderstanding from you.
A recordset is not an equivalent from a dataset.
A recordset is more an equivalent from a datatable.

A dataset can hold a lot of datatables.

I am starting to be aware of this - so a dataset is more like a
database??

Than as addition to Mike

First I set a reference to a datatable before I show you the samples
dim dt as datatable = ds.tables(0)

What means that we now can without much typing get that table
And when we than want to take a row from that than it is

dim dr as datarow

dr = dt.rows(current + 1)
dr = dt.rows(current - 1)


dr = dt.rows(current + 1)


dr = dt.rows(current - 1)

I hope this helps?


Yes - thanks to both of you. got a long road ahead of me!!!

Can I push my luck now - what about

rsRECORDSET.Find sCriteria

can't seem to locate anything on that...
 
A dataset is essentially an in-memory relational database, complete with
tables (datatables), relations, constraints, etc. Datasets can have
multiple tables, even from multiple databases. With recordsets, you could
specify server-side cursors: they don't exist with datasets. Datasets are
client-side/disconnected. With recordsets, you could navigate
forwards/backwards and have read/write access, or for performance reasons,
you could have a forward-only read-only recordset. Datasets allow the
forward/backward navigation as well as read/write access. There is a
separate object that provides the forward-only/read-only behaviour:
datareaders. To get data in and out of a dataset, you use dataadapters. To
provide data to datareaders, you use commands. (of course commands can also
be used in a stand-alone sense to run individual insert/update/delete
statements, if you know what you want to change and didn't need a dataset.)

How's that for a summary of the object model in ADO.Net?

Mike
 
A dataset is essentially an in-memory relational database, complete with
tables (datatables), relations, constraints, etc. Datasets can have
multiple tables, even from multiple databases. With recordsets, you could
specify server-side cursors: they don't exist with datasets. Datasets are
client-side/disconnected. With recordsets, you could navigate
forwards/backwards and have read/write access, or for performance reasons,
you could have a forward-only read-only recordset. Datasets allow the
forward/backward navigation as well as read/write access. There is a
separate object that provides the forward-only/read-only behaviour:
datareaders. To get data in and out of a dataset, you use dataadapters. To
provide data to datareaders, you use commands. (of course commands can also
be used in a stand-alone sense to run individual insert/update/delete
statements, if you know what you want to change and didn't need a dataset.)

How's that for a summary of the object model in ADO.Net?

Sounds pretty good to me! Thanks!
 
A dataset is essentially an in-memory relational database, complete with
tables (datatables), relations, constraints, etc. Datasets can have
multiple tables, even from multiple databases. With recordsets, you could
specify server-side cursors: they don't exist with datasets. Datasets are
client-side/disconnected. With recordsets, you could navigate
forwards/backwards and have read/write access, or for performance reasons,
you could have a forward-only read-only recordset. Datasets allow the
forward/backward navigation as well as read/write access. There is a
separate object that provides the forward-only/read-only behaviour:
datareaders. To get data in and out of a dataset, you use dataadapters. To
provide data to datareaders, you use commands. (of course commands can also
be used in a stand-alone sense to run individual insert/update/delete
statements, if you know what you want to change and didn't need a dataset.)


OK then,
Taking this a little further...

Normal in VB6 I would have on recordset for each "table" I was working
with.

I am now writing a database program in VB.net and wonder if I need to
change my thinking pattern.

I have 7 "tables" I need to refer to. Are you sugesting then that I
could load all 7 into one dataset and work with them in there? WOuld
that be better than one dataset for each table?

I am used to using:

sCrit = "DELETE * FROM TABLE WHERE..."

dbDATABASE.Execute sCRIT

to use SQL functions in my database.

How do I do this in VB.net as the Execute doesn't seem to exeist - and
the dbDATABASE *certainly* doesnt!!
 

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

Back
Top