PC Review


Reply
Thread Tools Rate Thread

ADO.Net transaction and ExecuteDataset

 
 
sam345.345@gmail.com
Guest
Posts: n/a
 
      5th Oct 2007
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

 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      7th Oct 2007
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TableNames with ExecuteDataSet Prefers Golfing Microsoft ADO .NET 1 7th Aug 2008 05:26 PM
ExecuteDataSet, Reader, non query and... Sugandh Jain Microsoft ADO .NET 1 14th Dec 2006 07:49 AM
Re: Error MSDAAB ExecuteDataset larzeb Microsoft ADO .NET 1 28th May 2005 03:03 AM
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." Ollie Riches Microsoft C# .NET 3 11th Mar 2005 05:23 PM
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." Ollie Riches Microsoft ADO .NET 3 11th Mar 2005 05:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.