ADO.Net transaction and ExecuteDataset

S

sam345.345

Hi,

I have clarification about ADO.Net transaction and ExecuteDataset;
In the "Microsoft Data Access Application Block for .NET" project the
following code uses transaction for ExecuteDataset()

What the purpose of using transaction in the ExecuteDataset()?

I think transaction is not use when retrieving data from a DB.

public static DataSet ExecuteDataset(SqlConnection connection,
CommandType commandType, string commandText, params SqlParameter[]
commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType,
commandText, commandParameters);

//create the DataAdapter & DataSet
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

//fill the DataSet using default values for DataTable names, etc.
da.Fill(ds);

// detach the SqlParameters from the command object, so they can be
used again.
cmd.Parameters.Clear();

//return the dataset
return ds;
}

Please anser to my question;

sampath
 
C

Cor Ligthert[MVP]

Hi,

In your code you don't need to connect to the dataset because the
DataAdapter has that intrensic in it.

I don't like your code, it is static, the same as the old way of using VB
(not in the new VB where probably only old classic VB programmers do this).
For the same you can call the class and than direct the method.

new TheClass().ExecuteDataset(...........)

All what you are creating goes than out of scope and will be cleaned up. You
don't need than instructions like: Clear the dataset to reuse it next time.

Cor
 

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

Top