How to get data from DB using FirebirdSql? ExecuteReader vs FbDataAdapter

IMAC

New member
Joined
May 16, 2010
Messages
2
Programming Experience
1-3
Hi

I have just started programming VB.net as i must make a program for a course at the university.
I am not familiar with it and i am having some problems trying to understand how the connection and SQL select commands works here.

Well, i am using FireBirdSQL as a database so i use this imports:
VB.NET:
Imports FirebirdSql.Data.FirebirdClient
Imports FirebirdSql.Data.Isql

Appart from it i declare this vars:

VB.NET:
Dim cmd As FbCommand
Dim dr As FbDataReader
Dim bbdd As BaseBBDD

And then i make the selection i want to get the data:
VB.NET:
 bbdd = New BaseBBDD(True)
            cmd = bbdd.crearComando("select * from cliente")

            dr = cmd.ExecuteReader()

            While dr.Read()
                Console.WriteLine("{0} Nombre: {1}      DNI: {2}", dr(0), dr(2), dr(1))
                WriteLine()
            End While
            Console.ReadLine()


The question is that i have seen other code that uses this other method:
VB.NET:
 bbdd = New BaseBBDD(True)
            Dim ds As New DataSet()
            Dim da As FbDataAdapter = bbdd.crearDataAdapter("SELECT * FROM mytable WHERE id >= @id")
            da.SelectCommand.Parameters.Add("@id", id)
            da.Fill(ds, "mytable")
            Return ds.Tables("mytable")

What is a DataAdapter? what advantages has it?
Why it uses da.SelectCommand.Parameters.Add("@id", id)? what does it do?
Whats the difference between ExecuteReader() and it?

What does da.Fill(ds, "mytable") do? What is "mytable"?

And about ds.Tables("mytable")?


I have tried to find information about this points on google, but i couldn't find anything with enought information for a noob...

Can you help me?

PD: sorry for my writting mistakes ;) Just not my language.
 
A DataReader provides read-only, forward-only access to your data. If you want to process your data as you retrieve it and then discard it, a DataReader is a good option. If you want random access to your data then you will want to populate a DataTable with it. You can populate a DataTable from a DataReader by calling DataTable.Load or you can use a DataAdapter by calling its Fill method. If you want to edit and then save your DataTable then you will definitely want to use a DataAdapter, because its Update method will save the changes in your DataTable.

A DataAdapter basically just groups four Commands together: one each to SELECT, DELETE, INSERT and UPDATE data. You can invoke these Commands easily with the Fill (for SELECT) and Update (for DELETE, INSERT and UPDATE) methods. Update will act on every row in the DataTable with changes.
 
Back
Top