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.
Siva M - 20 Jul 2007 13:26 GMT
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.
> Hi People,
>
[quoted text clipped - 14 lines]
>
> Thanks in advance.
Mark Rae [MVP] - 20 Jul 2007 13:58 GMT
> 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...

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