Sample code to use Sqlserver 2008 provider.

May 29, 2013 at 11:10 AM
Hi All,

I am using the SqlServer2008 to create some sample layer in the following way.
 layCounties.DataSource = new SqlServer2008(connectionString, "UScounties_1", "Shape", "oid", SqlServerSpatialObjectType.Geometry);
In the above method we are giving a fixed table name and the geometry column Name.
I would like to rather use a stored procedure to get my geometry and related values. Can anyone give me some way how to accomplish this.
Coordinator
May 29, 2013 at 11:35 AM
Edited May 29, 2013 at 11:37 AM
Stored procedures do take arguments, don't they?

If yours don't, you should be able to replace the table name with the name of the stored procedure. If not you'll have to modify the SqlServer2008 provider, or you create a view that invokes the stored procedure with the desired arguments.

Hth FObermaier
May 30, 2013 at 6:57 AM
FObermaier,


Thank you for the quick reply. and suggestions.

Just to confirm once again before I try changing the code to use as per my needs I hope changing the code in the

ExecuteIntersectionQuery in SqlServer2008 provider should work for me isnt it? or is there any other place I need to change the code ?

Arun
Coordinator
May 31, 2013 at 8:37 AM
Edited May 31, 2013 at 8:38 AM
To do it right, you'll have to investigate every query the provider makes and see if that is still correct.
I could imagine that the following approach would work.
  1. Add a property public Dictionary<string,object> StoredProcedureArguments { get; private set; }
  2. Look for every FROM clause that makes use of the table/stored procedure name. Make sure that if any StoredProcedureArguments were added that these are added to the Parameters collection of the command.
If that is done, pass the name of the stored procedure as tablename with all arguments, sth like testfn($PClass, $PTimeStamp). In this case you would add e.g.
sqlProvider.StoredProcedureArguments.Add("$PClass", 7);
sqlProvider.StoredProcedureArguments.Add("$PTimeStamp", DateTime.Now());
Hth FObermaier
Jun 1, 2013 at 10:15 AM
Hi Fobermaier,

Thanks for the lead. Will check and try and implement it . Will post if I have some doubts.

Thank you once again.

Regards
Arun