doubt on Connections and Dataadapters

S

Stewart

Hi People,

I have been coding in vb.net and c# for last six months, I am new to
coding and we are using 3 tier architecture. In the DAL in each and
every method I open the connection and close it in the finally block
of the try catch block, if I am not using a DataAdapter.
1. Is this correct?
2. should I be using only the dataadapter always, like for insertion
of single record, updation of single record, etc. The general practice
is to use the Dataadapter to only when a DataTable or Dataset comes
into picture.
3. Will there be any performance issues?

This question I have may be silly, but I need this. I want to have the
right code.
:)

Thanks in advance.
 
G

Guest

Data adapter is a sort of bridge between dataset/datatable and the actual
data source (such as SQL Server, Oracle, etc). So, you need a data adapter
instance when you want to fetch data from your DB or persist data changes
from dataset/datatable to the DB. There is no need to create a data adapter
otherwise.
 
M

Mark Rae [MVP]

I have been coding in vb.net and c# for last six months, I am new to
coding and we are using 3 tier architecture.

That's good.
In the DAL in each and every method I open the connection and close
it in the finally block of the try catch block, if I am not using a
DataAdapter.
1. Is this correct?

Yes, though an even easier method is to use the "using" syntax e.g.

using (SqlConnection SqlConn = new SqlConnection(SqlConnStr))
{
using (SqlCommand SqlComm = new SqlCommand(strSQL, SqlConn))
{

}
}
2. should I be using only the dataadapter always, like for insertion
of single record, updation of single record, etc.

No - you should be using the command object's ExecuteNonQuery method for
that...
The general practice is to use the Dataadapter to only when a DataTable
or Dataset comes into picture.
Correct.

3. Will there be any performance issues?

No - quite the reverse...
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top