using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SOASystem.Data.FileGDBClient;
using SOASystem.Data.GeoDataTypes;
using SOASystem.Data;

namespace FileGDBProviderTest
{
class ExecuteSQL
{
public static bool TestSQL()
{
FileGDBConnection conn = new FileGDBConnection();
conn.ConnectionString = @"database=C:\FileGDBProvider\data\ExecuteSQL.gdb";
conn.Open();

String sql = "SELECT * FROM Cities WHERE TERM = 'City'";
FileGDBCommand cmd = new FileGDBCommand(sql, conn);

// return the first row ObjectID that sataify the SQL query
int oid = cmd.ExecuteNonQuery();

FileGDBDataReader reader = cmd.ExecuteReader() as FileGDBDataReader;

// Can get the table info using the ITableInfo interface.
// Info like RowCount reflect the total count of rows in
// the table rather than the ones that returns from the SQL query.
// If you need to get that count, use the GeoDataSet instead.
//
ITableInfo iTInfo = reader as ITableInfo;
long rowCount = iTInfo.RowCount;

//while (reader.Read())
//{
// int cityPop = -1;
// bool success = Int32.TryParse(reader["Pop1996"].ToString(), out cityPop);
// GeoDataString cityName = (GeoDataString)reader["Name"];
//}

DataTable dTable = reader.GetSchemaTable();

while (reader.Read())
{
foreach (DataRow r in dTable.Rows)
{
Type t = r["DataType"] as Type;
String name = r["ColumnName"] as String;
object obj;
int index = reader.GetOrdinal(name);
if (t == typeof(Int16))
obj = reader.GetInt16(index);
else if (t == typeof(Int32))
obj = reader.GetInt32(index);
else if (t == typeof(GeoDataString))
obj = reader.GetString(index);
else if (t == typeof(Guid))
obj = reader.GetGuid(index);
else if (t.GetInterface("IGeometry") == typeof(IGeometry))
{
IGeometry iG = reader.GetValue(index) as IGeometry;
switch (iG.GeometryType)
{
case GeometryType.GeometryTypePoint:
Point p = (Point)iG;
break;
case GeometryType.GeometryTypeMultiPoint:
MultiPoint mp = iG as MultiPoint;
break;
case GeometryType.GeometryTypePolyline:
Polyline pl = iG as Polyline;
break;
case GeometryType.GeometryTypePolygon:
Polygon poly = iG as Polygon;
break;
case GeometryType.GeometryTypeMultiPatch:
MultiPatch mPatch = iG as MultiPatch;
break;
default:
break;

}
}

}
}

reader.Close();
conn.Close();
return true;
}
}
}

Last edited Aug 25, 2011 at 6:17 PM by dotnetprovider, version 1

Comments

No comments yet.