MSSQL and MsSqlSpatial providers

Topics: Data Access, Español, General Topics, SharpMap v2.0
Aug 28, 2007 at 6:41 AM

A simple question, why "Columns" property are not implemented (it throw an exception)?
(In MsSqlSpatial provider the code is commented). May be there a logical reason to this.

If there aren't any spetial reason I can implemented it (or I can try :-) )

Una pregunta rápida, por qué la propiedad "Columns" no está implementada (lanza una excepción)?
(En el proveedor de datos MsSqlSpatial el código está comentado). Tal vez exista alguna razón lógica para ello.

Si no existe ninguna razón especial yo puedo implementarla (o intentarlo :-) )
Aug 28, 2007 at 8:21 AM
Hi Hameeg -

You can feel free to implement the Columns yourself. I'm not sure of the reason for the lack of support in v1.0. You can query on an empty region via ExecuteIntersectionQuery on the provider to get the columns in a FeatureDataTable, and this works for all providers, not just MsSqlSpatial. Although this is a bit indirect and is perhaps not the best way to get schema, it works.

In v2.0, both the IFeatureDataReader and IVectorLayerProvider types have a GetSchemaTable method which should be implemented by readers and providers. This method and the returned DataTable which descibes schema mirrors what is found in ADO.Net.
Aug 28, 2007 at 9:28 AM
Hi codekaizen,

Sorry, I check an extra option (SharpMap v1.0). I'm using v2.0.

Where are these types? I don't find them. I only find the GetSchemaTable in DbaseReader. It's a method to implement? Now I'm a little over lost...

Thank you for answering me so fast

Hola codekaizen,

Perdona, pero chequeé una opción extra (SharpMap v1.0). Estoy usando la v2.0.

¿Dónde están estos tipos? No los encuentro. Sólo encuentro el GetSchemaTable en DbaseReader. ¿Es un método para implementar? Ahora estoy un poco más perdido...

Gracias por contestarme tan rápido.
Aug 28, 2007 at 1:56 PM
Hi again,

Now I understand you. Tomarrow I'll try to implement this.


Hola otra vez,

Ahora te entiendo. Mañana intentaré implementarlo.

Aug 29, 2007 at 2:28 PM

At last I'm write this:

public System.Data.DataColumnCollection Columns
DataTable oSchema = null;

using (SqlConnection conn = new SqlConnection(_ConnectionString))
string strSQL = "SELECT * FROM " + this.Table + " WHERE 1=2";
using (SqlCommand command = new SqlCommand(strSQL, conn))
using (SqlDataReader dr = command.ExecuteReader())
oSchema = dr.GetSchemaTable();

DataTable oDt = new DataTable("MSSQLSchema");

foreach (DataRow oRow in oSchema.Rows)
DataColumn oDC = new DataColumn();
foreach (DataColumn oColumn in oSchema.Columns)
oDC.ExtendedProperties.Add(oColumn.ColumnName, oRowoColumn);
oDC.ColumnName = oDC.ExtendedProperties"ColumnName".ToString();
oDC.DataType = (Type) oDC.ExtendedProperties"DataType";

return oDt.Columns;

May be it could be util someone...


Al final he escrito ésto:

(ver código más arriba)

Tal vez sea útil para alguien...
Aug 29, 2007 at 4:32 PM
Hameeg -

Thanks for the contrib!

If you'd post it in the patches area, here:, users looking for enhanced functionality might be able to find it more readily.
Aug 30, 2007 at 6:39 AM
Of course. Which is the best way to do: upload only the file modified or all project?


Claro. ¿Cuál es la mejor manera de hacerlo?: ¿subir sólo el fichero modificado o todo el proyecto entero?