How to set the data.provider.MSSQL with a SQL view?

Topics: Data Access, SharpMap Project, WinForms Controls
Jun 21, 2010 at 4:44 PM
Hi, everyone I created some views in my mssql2005 management studio, and I want to use these views as some of my layers'datasouce. I know how to use a table as the datasouce, like the code below: myLayer.DataSource = new SharpMap.Data.Providers.MsSql(conn, "myTableColumn", "WKB_Geometry", "oid"); but if I want to use a view named "myViewColumn" to instead the table named myTableColumn as mylayer's datasouce, what should I do? Any help will be appreciated! Ichelite :)
Coordinator
Jun 21, 2010 at 5:29 PM

Hello Ichelite,

I havn't tried to use views with MsSql Provider (infact, I havn't used it at all) but you should be fine using views if your views obey the same rules as the tables need to do:

  • have one uint32 column for the object identifier
  • have a binary or image column containing the WKB geometry data
  • have four double columns containing the envelope extents. These must be named Envelope_MinX, Envelope_MaxX, Envelope_MinY, Envelope_MaxY

To set up your Datasource just replace the tableName with the name of the stored view.

Hth FObermaier

Jun 21, 2010 at 11:54 PM

Hi Fobermaier,

Thank you so much for your help. your three rules saved me a lot of time in dealing with joining tables.

Now I have made it by using views with Mssql provider.

Ichelite:)