本文整理汇总了C#中Npgsql.NpgsqlCommand.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlCommand.GetString方法的具体用法?C# NpgsqlCommand.GetString怎么用?C# NpgsqlCommand.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Npgsql.NpgsqlCommand
的用法示例。
在下文中一共展示了NpgsqlCommand.GetString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSpatialObjectType
/// <summary>
/// Queries the data t
/// </summary>
/// <returns></returns>
private PostGisSpatialObjectType GetSpatialObjectType()
{
var sql = string.Format("SELECT \"udt_name\" from \"information_schema\".\"columns\" " +
"WHERE \"table_schema\"='{0}' AND \"table_name\"='{1}' AND \"column_name\"='{2}';",
_schema, _table, _geometryColumn);
using (var conn = new NpgsqlConnection(ConnectionString))
{
conn.Open();
using (var rdr = new NpgsqlCommand(sql, conn).ExecuteReader())
{
if (rdr.HasRows)
{
rdr.Read();
switch (rdr.GetString(0))
{
case "geometry":
return PostGisSpatialObjectType.Geometry;
case "geography":
_geometryCast = "::geometry";
return PostGisSpatialObjectType.Geography;
default:
throw new ArgumentException(
"Provided geometry/geography column name does not yield geometry/geography data");
}
}
}
throw new NotSupportedException("Could not find geometry column within tables, need to check view definition");
}
}
示例2: GetNonSpatialColumns
/// <summary>
/// Get the non-spatial columns
/// </summary>
private void GetNonSpatialColumns()
{
if (!string.IsNullOrEmpty(_columns))
return;
if (string.IsNullOrEmpty(ConnectionID))
return;
using (var conn = new NpgsqlConnection(ConnectionString))
{
conn.Open();
using (var dr = new NpgsqlCommand(string.Format(
"SELECT \"column_name\" FROM \"information_schema\".\"columns\" "+
"WHERE \"table_schema\"='{0}' AND \"table_name\"='{1}';", Schema, Table), conn).ExecuteReader())
{
if (!dr.HasRows)
throw new InvalidOperationException("Provider configuration incomplete or wrong!");
var columns = new List<string>{ "\"" + ObjectIdColumn + "\"" };
while (dr.Read())
{
var column = dr.GetString(0);
if (string.Equals(column, ObjectIdColumn)) continue;
if (string.Equals(column, GeometryColumn)) continue;
columns.Add(string.Format("\"{0}\"", column));
}
_columns = string.Join(", ", columns);
}
}
}