SqlDataSource has two kinds of fetching out data contents, one of which is DataTable or DataSet, while the other is DataReader. So for the first situation, it should be slower than Reader because it will execute the SQL statement and Fill into a DataTable
and bind to the GridView. Compared with this, SqlDataSource can have DataReader, which should equal to a common SqlDataReader because it's referring that.
This is the reflected codes:
[WebCategory("Behavior"), DefaultValue(1), WebSysDescription("SqlDataSource_DataSourceMode")]
public SqlDataSourceMode DataSourceMode
{
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
get
{
return this._dataSourceMode;
}
set
{
if ((value < SqlDataSourceMode.DataReader) || (value > SqlDataSourceMode.DataSet))
{
throw new ArgumentOutOfRangeException(SR.GetString("SqlDataSource_InvalidMode", new object[] { this.ID }));
}
if (this.DataSourceMode != value)
{
this._dataSourceMode = value;
this.RaiseDataSourceChangedEvent(EventArgs.Empty);
}
}
}
When you set the DataSource mode, it will raise the event:
Diomedes
Member
202 Points
145 Posts
SqlDataSource or SqlHelper.ExecuteReader
Dec 07, 2012 02:07 AM|LINK
Hi,
In your guys opinions, which one is more effective: SqlDataSource or SqlHelper.ExecuteReader.
Thanks
march11
Contributor
2981 Points
1350 Posts
Re: SqlDataSource or SqlHelper.ExecuteReader
Dec 07, 2012 06:43 PM|LINK
Depends on what you are trying to do.
I use SqlDataSource a lot. but I also use reader.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource or SqlHelper.ExecuteReader
Dec 08, 2012 02:09 AM|LINK
SqlDataSource has two kinds of fetching out data contents, one of which is DataTable or DataSet, while the other is DataReader. So for the first situation, it should be slower than Reader because it will execute the SQL statement and Fill into a DataTable and bind to the GridView. Compared with this, SqlDataSource can have DataReader, which should equal to a common SqlDataReader because it's referring that.
This is the reflected codes:
[WebCategory("Behavior"), DefaultValue(1), WebSysDescription("SqlDataSource_DataSourceMode")] public SqlDataSourceMode DataSourceMode { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get { return this._dataSourceMode; } set { if ((value < SqlDataSourceMode.DataReader) || (value > SqlDataSourceMode.DataSet)) { throw new ArgumentOutOfRangeException(SR.GetString("SqlDataSource_InvalidMode", new object[] { this.ID })); } if (this.DataSourceMode != value) { this._dataSourceMode = value; this.RaiseDataSourceChangedEvent(EventArgs.Empty); } } }When you set the DataSource mode, it will raise the event:
protected virtual void RaiseDataSourceChangedEvent(EventArgs e) { this.OnDataSourceChangedInternal(e); this.OnDataSourceChanged(e); }