I am working on a large winforms app that uses datasets created in visual studio. Access/Updates in the source generally look like:
trans = conn.BeginTransaction();
orderDA.UpdateCommand.Transaction = trans;
orderDA.InsertCommand.Transaction = trans;
orderDA.DeleteCommand.Transaction = trans;
orderDA.Update(ds);
trans.Commit();
ds.AcceptChanges();
where OrderDA appears to be a dataadapter. When I step through this in the debugger, I can see the stored procedure names used for SelectCommand, InsertCommand, etc. But I cannot find where the stored procedures are initially set, either in the dataset
or programically. Its a lot of code, and before I go too much deeper into it, I wanted to determine if there is an obvious place to look. Ive brought up the dataset in vs and hoped they would be exposed as properties, but I couldnt find them. Can anyone let
me know where to look?
ut I cannot find where the stored procedures are initially set, either in the dataset or programically. Its a lot of code, and before I go too much deeper into it, I wanted to determine if there is an obvious place to look.
Hello:)
An interesting question here……Haha,Now in fact I recommand you use something like Reflector(Non-Free)or Telerik Just-DeCompiler,ILSpy(Both are free)or something related that can translate dll into .NET codes。
In fact,when you set a stored procdure for Delete, Update or Select Insert command,all of them——in fact are SqlCommands instance。So you can actually do something to assign them by:
adapter.XXXCommmand.Property=value……;
To assign them。
I guess you are using something like SqlCommandBuilder,if so,this will generate CRUD methods and assign to the four commands dynamcially——Here's reflected codes from Telerik's Just-DeCompiler("GetUpdateCommand" for an example——)
1)GetUpdateCommand calls its base class DBCommand:
public SqlCommand GetUpdateCommand()
{
return (SqlCommand)base.GetUpdateCommand();
}
2)Base class's returns a general DbCommand:
public DbCommand GetUpdateCommand()
{
return this.GetUpdateCommand(null, false);
}
3)In the GetUpdateCommand's function——Notice that it's generated codes:
Turns out I didnt have to use a decompiler, just a "Find in Files". The stored procedures were named in a .desiger.cs file ... so I knew they were set visually. Turns out the developer dragged dataadapters onto some type of visual element - Im not exactly
certain what they were, the file inherited from "Component" - and set them in properties. Thanks for your help.
Oh, and regarding decompiliers - I think Jetbrains has one, and there is also an open source version. I think there is still a free version of Reflector, although the vendors want you to upgrade.
First congratulation to your turnning out your problem!My addition——
In fact I think you can use Reflector,if you have enough memory to pay for that……Its professional version directly supports "Debugging without source codes……"
SandpointGuy
Member
33 Points
39 Posts
stored procedures imbedded in dataset
May 02, 2012 12:45 AM|LINK
I am working on a large winforms app that uses datasets created in visual studio. Access/Updates in the source generally look like:
trans = conn.BeginTransaction();
orderDA.UpdateCommand.Transaction = trans;
orderDA.InsertCommand.Transaction = trans;
orderDA.DeleteCommand.Transaction = trans;
orderDA.Update(ds);
trans.Commit();
ds.AcceptChanges();
where OrderDA appears to be a dataadapter. When I step through this in the debugger, I can see the stored procedure names used for SelectCommand, InsertCommand, etc. But I cannot find where the stored procedures are initially set, either in the dataset or programically. Its a lot of code, and before I go too much deeper into it, I wanted to determine if there is an obvious place to look. Ive brought up the dataset in vs and hoped they would be exposed as properties, but I couldnt find them. Can anyone let me know where to look?
Thanks very much for your time.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: stored procedures imbedded in dataset
May 04, 2012 02:46 AM|LINK
Hello:)
An interesting question here……Haha,Now in fact I recommand you use something like Reflector(Non-Free)or Telerik Just-DeCompiler,ILSpy(Both are free)or something related that can translate dll into .NET codes。
In fact,when you set a stored procdure for Delete, Update or Select Insert command,all of them——in fact are SqlCommands instance。So you can actually do something to assign them by:
adapter.XXXCommmand.Property=value……;
To assign them。
I guess you are using something like SqlCommandBuilder,if so,this will generate CRUD methods and assign to the four commands dynamcially——Here's reflected codes from Telerik's Just-DeCompiler("GetUpdateCommand" for an example——)
1)GetUpdateCommand calls its base class DBCommand:
public SqlCommand GetUpdateCommand() { return (SqlCommand)base.GetUpdateCommand(); }2)Base class's returns a general DbCommand:
public DbCommand GetUpdateCommand() { return this.GetUpdateCommand(null, false); }3)In the GetUpdateCommand's function——Notice that it's generated codes:
4)And continue to BuildUpdateCommand——
private DbCommand BuildUpdateCommand(DataTableMapping mappings, DataRow dataRow) { DbCommand str = this.InitializeCommand(this.UpdateCommand); StringBuilder stringBuilder = new StringBuilder(); string str1 = " SET "; int num = 0; stringBuilder.Append("UPDATE "); stringBuilder.Append(this.QuotedBaseTableName); DbSchemaRow[] dbSchemaRowArray = this._dbSchemaRows; for (int i = 0; i < (int)dbSchemaRowArray.Length; i++) { DbSchemaRow dbSchemaRow = dbSchemaRowArray[i]; if (dbSchemaRow != null && dbSchemaRow.BaseColumnName.Length != 0 && this.IncludeInUpdateSet(dbSchemaRow)) { object columnValue = null; string str2 = this._sourceColumnNames[i]; if (mappings != null && dataRow != null) { DataColumn dataColumn = this.GetDataColumn(str2, mappings, dataRow); if (dataColumn != null && (!dbSchemaRow.IsReadOnly || !dataColumn.ReadOnly)) { columnValue = this.GetColumnValue(dataRow, dataColumn, DataRowVersion.Current); if (!this.SetAllValues) { object obj = this.GetColumnValue(dataRow, dataColumn, DataRowVersion.Original); if (obj == columnValue || obj != null && obj.Equals(columnValue)) { goto Label0; } } } else { goto Label0; } } stringBuilder.Append(str1); str1 = ", "; stringBuilder.Append(this.QuotedColumn(dbSchemaRow.BaseColumnName)); stringBuilder.Append(" = "); stringBuilder.Append(this.CreateParameterForValue(str, this.GetBaseParameterName(i), str2, DataRowVersion.Current, num, columnValue, dbSchemaRow, StatementType.Update, false)); num++; } Label0: } bool flag = 0 == num; num = this.BuildWhereClause(mappings, dataRow, stringBuilder, str, num, true); str.CommandText = stringBuilder.ToString(); DbCommandBuilder.RemoveExtraParameters(str, num); this.UpdateCommand = str; if (flag) { return null; } else { return str; } }SandpointGuy
Member
33 Points
39 Posts
Re: stored procedures imbedded in dataset
May 04, 2012 02:41 PM|LINK
Turns out I didnt have to use a decompiler, just a "Find in Files". The stored procedures were named in a .desiger.cs file ... so I knew they were set visually. Turns out the developer dragged dataadapters onto some type of visual element - Im not exactly certain what they were, the file inherited from "Component" - and set them in properties. Thanks for your help.
Oh, and regarding decompiliers - I think Jetbrains has one, and there is also an open source version. I think there is still a free version of Reflector, although the vendors want you to upgrade.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: stored procedures imbedded in dataset
May 05, 2012 12:26 AM|LINK
Hello SandpointGuy:)
First congratulation to your turnning out your problem!My addition——
In fact I think you can use Reflector,if you have enough memory to pay for that……Its professional version directly supports "Debugging without source codes……"
For more you can refer this:
http://www.reflector.net/vspro/