當前位置: 首頁>>代碼示例>>C#>>正文


C# NpgsqlCommand.GetString方法代碼示例

本文整理匯總了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");
            }
        }
開發者ID:junglewithyou,項目名稱:SharpMap,代碼行數:34,代碼來源:PostGIS.cs

示例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);
                }
            }
        }
開發者ID:junglewithyou,項目名稱:SharpMap,代碼行數:34,代碼來源:PostGIS.cs


注:本文中的Npgsql.NpgsqlCommand.GetString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。