Beispiel #1
0
        private static List <DbNnColumn> GetDbColumnSchema()
        {
            //get the database column schema
            SqlDataReader rdr       = null;
            var           dbColList = new List <DbNnColumn>();
            var           strConn   = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();

            using (var conn = new SqlConnection(strConn))
            {
                try
                {
                    var cmd = new SqlCommand("SELECT * FROM Novanet", conn);
                    conn.Open();

                    rdr = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
                    for (int i = 0; i < rdr.FieldCount; i++)
                    {
                        var col = new DbNnColumn
                        {
                            Name     = rdr.GetName(i),
                            DataType = rdr.GetDataTypeName(i)
                        };

                        dbColList.Add(col);
                        var fieldType = rdr.GetFieldType(i);
                        if (fieldType != null)
                        {
                            col.FieldType = fieldType.ToString();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                finally
                {
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                }
            }//using (var conn = new SqlConnection(strConn))
            return(dbColList);
        }
Beispiel #2
0
        private static List<DbNnColumn> GetDbColumnSchema()
        {
            //get the database column schema
            SqlDataReader rdr = null;
            var dbColList = new List<DbNnColumn>();
            var strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();
            using (var conn = new SqlConnection(strConn))
            {
                try
                {

                    var cmd = new SqlCommand("SELECT * FROM Novanet", conn);
                    conn.Open();

                    rdr = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
                    for (int i = 0; i < rdr.FieldCount; i++)
                    {
                        var col = new DbNnColumn
                                  {
                                      Name = rdr.GetName(i),
                                      DataType = rdr.GetDataTypeName(i)
                                  };

                        dbColList.Add(col);
                        var fieldType = rdr.GetFieldType(i);
                        if (fieldType != null)
                        {
                            col.FieldType = fieldType.ToString();
                        }

                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                finally
                {
                    if (rdr != null)
                        rdr.Close();
                }
            }//using (var conn = new SqlConnection(strConn))
            return dbColList;
        }