示例#1
0
        public void readFromDataBase()
        {
            items.Clear();
            SqlDataReader reader = new SqlCommand(string.Format("SELECT * FROM Items ORDER BY Id;SELECT * FROM Jobs ORDER BY Item;SELECT * FROM Jobs ORDER BY Item;"), cn).ExecuteReader();
            //читаем лист items
            while (reader.Read())
            {
                item newItem = new item();
                newItem.id = reader.GetInt32(0);
                newItem.firstName = reader.GetString(1);
                newItem.lastName = reader.GetString(2);
                items.Add(newItem);
            }

            int i;
            int lastid;

            //читаем лист jobs
            reader.NextResult();
            lastid = i = -1;
            while (reader.Read())
            {
                int k = reader.GetInt32(4);
                if (lastid != k)
                {
                    do ++i;
                    while (k != items[i].id);
                    lastid = reader.GetInt32(4);
                }
                items[i].jobs.Add(new job(reader.GetDateTime(0), reader.GetString(1), reader.GetString(2), reader.GetString(3)));
            }

            //читаем лист positions
            reader.NextResult();
            lastid = i = -1;
            while (reader.Read())
            {
                if (lastid != reader.GetInt32(4))
                {
                    do i++;
                    while (reader.GetInt32(4) != items[i].id);
                    lastid = reader.GetInt32(4);
                }
                items[i].positions.Add(new position(reader.GetInt64(0),reader.GetInt64(1),reader.GetInt32(2),reader.GetDateTime(3)));
            }
            reader.Close();
        }
示例#2
0
 public List<LinkedDatabase> GetLinkedDatabaseList()
 {
     if (!this.IsSqlServer)
     {
         throw new NotSupportedException("This operation is supported only for SQL Server.");
     }
     StringBuilder builder = new StringBuilder();
     List<string> list = new List<string>();
     List<LinkedDatabase> list2 = new List<LinkedDatabase>();
     string cmdText = "select data_source from sys.servers where provider = 'SQLNCLI' and is_linked = 1";
     using (SqlConnection connection = new SqlConnection(this.GetCxString()))
     {
         SqlDataReader reader;
         connection.Open();
         using (reader = new SqlCommand(cmdText, connection).ExecuteReader())
         {
             while (reader.Read())
             {
                 string item = reader[0].ToString();
                 list.Add(item);
                 builder.AppendLine("select name from [" + item + "].[master].[sys].[databases]");
             }
         }
         int num = 0;
         using (reader = new SqlCommand(builder.ToString(), connection).ExecuteReader())
         {
             while (reader.Read())
             {
                 list2.Add(new LinkedDatabase(list[num], reader[0].ToString()));
                 continue;
             Label_00D6:
                 if (!reader.NextResult())
                 {
                     return list2;
                 }
                 num++;
             }
             goto Label_00D6;
         }
     }
 }