 |
|
 |
Hi,
I am using the report viewer object in my class, and using objectDatasource as the datasoure.The typename is set the the tableadapter.
I try to use the way you specificedf to modify the commandTimeout value, however, I got the following error. I am new to C#, I hope someone could point me to the right direction.
'Report.App_Code.rp_demand_saving_wrapperTableAdapter' does not contain a definition for '_adapter' and no extension method '_adapter' accepting a first argument of type 'Report.App_Code.rp_demand_saving_wrapperTableAdapter' could be found (are you missing a using directive or an assembly reference?)
This is the code of the parital class
namespace Report.App_Code.demandTableAdapters
{
public partial class rp_demand_saving_wrapperTableAdapter
{
public int InsertCommandTimeout
{
get
{
return (this._adapter.InsertCommand.CommandTimeout);
}
set
{
this._adapter.InsertCommand.CommandTimeout = value;
}
}
public int UpdateCommandTimeout
{
get
{
return (this._adapter.UpdateCommand.CommandTimeout);
}
set
{
this._adapter.UpdateCommand.CommandTimeout = value;
}
}
public int DeleteCommandTimeout
{
get
{
return (this._adapter.DeleteCommand.CommandTimeout);
}
set
{
this._adapter.DeleteCommand.CommandTimeout = value;
}
}
public int SelectCommandTimeout
{
get
{
return (this._commandCollection[0].CommandTimeout);
}
set
{
for (int i = 0; i < this._commandCollection.Length; i++)
{
if ((this._commandCollection[i] != null))
{
((System.Data.SqlClient.SqlCommand)
(this._commandCollection[i])).CommandTimeout = value;
}
}
}
}
}
}
|
|
|
|
 |
|
 |
I tried this code and as mentioned in an earlier post had to change ._commandCollection to .CommandCollection I don't know if this is a difference in VS 2008 although I am still using the .NET framework 2.0 so shouldn't be a different method. Can you change this in the post please or note it as I (as I am sure many have) spend quite a bit of time trying to work out why I couldn't get your partial class to work until I came back and actually read the old posts.
Pete
|
|
|
|
 |
|
 |
Yeap, same problem for me (Visual Studio 2005, C#, .NET Framework 2.0); with the original code I have this exception :
System.NullReferenceException: Object reference not set to an instance of an object.
at XXXX.dsGetProduseNomenclator_TableAdapters.getProduseNomenclatorTableAdapter.set_SelectCommandTimeout(Int32 value) in ....
After I changed _commandCollection with CommandCollection everything works fine.
|
|
|
|
 |
|
 |
For People who require the VB version... '========================================================================= Namespace xxxTableAdapters Partial Public Class xxxTableAdapter Public Property SelectCommandTimeout() As Integer Get Return (Me.CommandCollection(0).CommandTimeout) End Get Set(ByVal Value As Integer) Dim i As Integer For i = 0 To Me.CommandCollection.Length - 1 Step i + 1 If (Me.CommandCollection(i) IsNot Nothing) Then Me.CommandCollection(i).CommandTimeout = Value End If Next End Set End Property End Class End Namespace '===========================================================================
|
|
|
|
 |
|
 |
Every example I see to extend the table adapter uses a partial class to do so like this example. But what I don't get is if you have a wizard created typed dataset that uses a generated table adapter like with the SQL Report Viewer Control. How do you get it to use your extended class properties?
|
|
|
|
 |
|
 |
Examine the generated file to see what the name of the class is, then write your code to match.
|
|
|
|
 |
|
 |
I did match the class name and namespace name up and can see the object members now.
I could overload a method like the GetData method but I would still need to be able to call the overloaded method somewhere which is what I don't get since you can't really touch the generated code to call your overloaded method?
I know I am missing the point somewhere, I just need to figure out where.
Where would you put this line of code at? this.xxxTableAdapter.SelectCommandTimeout = 0 ;
|
|
|
|
 |
|
 |
rckrll4ever wrote: I could overload a method like the GetData method
Overload maybe; but if you mean override, you can't because you're not deriving a new class.
rckrll4ever wrote: Where would you put this line of code at?
In the class that uses the DataSet, but it's been so long since I've used a DataSet that I've forgotten.
|
|
|
|
 |
|
 |
PIEBALDconsult wrote: Overload maybe; but if you mean override, you can't because you're not deriving a new class.
Yep I meant overload because I can't figure anything else out, but this is the wrong idea probably.
PIEBALDconsult wrote: In the class that uses the DataSet, but it's been so long since I've used a DataSet that I've forgotten.
Well in my case the dataset is used by an objectDataSource object that the report viewer uses for it's data. But I couldn't figure out any way to set the timeout value there.
|
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
I am having the same issue. How did you call the code?
|
|
|
|
 |
|
 |
Perhaps you should have replied to the earlier poster. I don't do VB, and I haven't used the information in the article for a long time.
Plus, my head is all stuffed up and I can't think.
|
|
|
|
 |
|
 |
I was having trouble making this work, but the tutorial above explained it and I was able to get it working for my app. Now on to the next step...
|
|
|
|
 |
|
 |
A convenient way to set up COMMAND TIMEOUT properties for SQLDataSource and DataSet objects:
DataSet
Use it like this (presuming you have "CommandTimeoutSeconds" in web.config):
xxxTableAdapters.xxxTableAdapter adapter = new xxxTableAdapters.xxxTableAdapter();
adapter.CommandTimeout = int.TryParse(ConfigurationManager.AppSettings["CommandTimeoutSeconds"];
adapter.DoStuff();
Code snipp:
namespace xxx.xxxTableAdapters
{
public partial class xxxTableAdapter
{
public int CommandTimeout
{
set
{
this.InsertCommandTimeout = value;
this.UpdateCommandTimeout = value;
this.SelectCommandTimeout = value;
this.DeleteCommandTimeout = value;
}
}
public int InsertCommandTimeout
{
set
{
if (this.Adapter.InsertCommand != null) this.Adapter.InsertCommand.CommandTimeout = value;
}
}
public int UpdateCommandTimeout
{
set
{
if (this.Adapter.UpdateCommand != null) this.Adapter.UpdateCommand.CommandTimeout = value;
}
}
public int DeleteCommandTimeout
{
set
{
if (this.Adapter.DeleteCommand != null) this.Adapter.DeleteCommand.CommandTimeout = value;
}
}
public int SelectCommandTimeout
{
set
{
for (int i = 0; i < this.CommandCollection.Length; i++)
{
if ((this.CommandCollection[i] != null))
{
((System.Data.SqlClient.SqlCommand)
(this.CommandCollection[i])).CommandTimeout = value;
}
}
if (this.Adapter.SelectCommand != null) this.Adapter.SelectCommand.CommandTimeout = value;
}
}
}
}
SQLDataSource
Use it like this - in PageLoad section put the following snipp (presuming you have SQLDataSource someSQLDataSource on the page and "CommandTimeoutSeconds" in web.config):
DataSourceTimeout.Update(someSQLDataSource);
Code snipp:
public static class DataSourceTimeout
{
private static int mValue;
static DataSourceTimeout()
{
int.TryParse(ConfigurationManager.AppSettings["CommandTimeoutSeconds"], out mValue);
}
public static int Value
{
get { return mValue; }
set { mValue = value; }
}
public static void Update(SqlDataSource source)
{
source.Selecting += new SqlDataSourceSelectingEventHandler(source_Selecting);
source.Inserting += new SqlDataSourceCommandEventHandler(source_Command);
source.Updating += new SqlDataSourceCommandEventHandler(source_Command);
source.Deleting += new SqlDataSourceCommandEventHandler(source_Command);
}
private static void source_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.CommandTimeout = mValue;
}
static void source_Command(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.CommandTimeout = mValue;
}
}
Hope it helps,
Aleksander
|
|
|
|
 |
|
 |
1) Adapter needs to be initialized
2) Sometimes it is not known what type of statement is used (select, insert...) in case of stored procedure
Code snipp:
namespace xxx.xxxTableAdapters
{
public partial class xxxTableAdapter
{
public int CommandTimeout
{
set
{
this.InsertCommandTimeout = value;
this.UpdateCommandTimeout = value;
this.SelectCommandTimeout = value;
this.DeleteCommandTimeout = value;
}
}
public int InsertCommandTimeout
{
set
{
if(this.Adapter.InsertCommand != null) this.Adapter.InsertCommand.CommandTimeout = value ;
}
}
public int UpdateCommandTimeout
{
set
{
if(this.Adapter.UpdateCommand != null) this.Adapter.UpdateCommand.CommandTimeout = value ;
}
}
public int DeleteCommandTimeout
{
set
{
if (this.Adapter.DeleteCommand != null) this.Adapter.DeleteCommand.CommandTimeout = value;
}
}
public int SelectCommandTimeout
{
set
{
for ( int i = 0 ; i < this.CommandCollection.Length ; i++ )
{
if ( ( this.CommandCollection [ i ] != null ) )
{
((System.Data.SqlClient.SqlCommand)
(this.CommandCollection [ i ])).CommandTimeout = value;
}
}
if (this.Adapter.SelectCommand != null) this.Adapter.SelectCommand.CommandTimeout = value;
}
}
}
}
Hope it helps,
Aleksander
|
|
|
|
 |
|
 |
gmhwn wrote: 1) Adapter needs to be initialized
2) Sometimes it is not known what type of statement is used (select, insert...) in case of stored procedure
1) Isn't that handled by the auto-generated code?
2) So what?
|
|
|
|
 |
|
 |
Why loop through the select commands? At any time there is only one active select command. The command collection may contain many queries, but Adapter.SelectCommand will be set to which ever one you are using.
Based on this logic you should loop through the insert, update and delete commands also.
|
|
|
|
 |
|
 |
It seemed necessary at the time, but it's been so long and I avoid DataAdapters anyway.
|
|
|
|
 |
|
 |
I applaud the author for this handy piece of code. It addressed precisely the problem I was having. I did find one minor glitch, though: I had to change "_commandCollection" to "CommandCollection" as the former was null while the latter had reasonable data. With that minor change, it works exactly as advertised. Thank you!
~~Michael Sorens
Software Consultant
Open Source Developer (http://cleancode.sourceforge.net)
Occasional Adjunct Faculty
|
|
|
|
 |
|
 |
I'll try to remember that if I ever have to use the code myself (I originally wrote it for a colleague).
It would be great if other users would let me know if they found the same problem.
|
|
|
|
 |
|
 |
By trial and error, I arrived at this:
public int SelectCommandTimeout
{
get
{
return this.CommandCollection[0] .CommandTimeout;
}
set
{
this.CommandCollection[0].CommandTimeout = value;
}
}
If SelectCommand will always be [0], why not just do it this way. I found TWO problems with your original code (although I thank you PROFUSELY for the idea!):
|
|
|
|
 |
|
 |
Because that would be wrong. But you can do what you like.
|
|
|
|
 |
|
 |
To be clearer...
A TableAdapter, when used to fill a DataSet with multiple DataTables, will have a select command for each DataTable. These commands are in the _commandCollection. When setting a property that should apply to each, one needs to traverse the collection setting them.
If you know how many you have, you may go right ahead and hard code that value, but it could increase the maintenance required down the road with very little gained.
Another technique would be to add the ability to access the property on each select command individually.
|
|
|
|
 |