Example #1
0
        /// <summary>
        /// Fill
        /// </summary>
        /// <param name="dt"></param>
        public void Fill(DataTable dt)
        {
            if (dt == null)
            {
                dt = new DataTable();
            }
            var columns = dt.Columns;
            var rows    = dt.Rows;

            using (DmDataReader dr = command.ExecuteReader())
            {
                for (int i = 0; i < dr.FieldCount; i++)
                {
                    string name = dr.GetName(i).Trim();
                    if (!columns.Contains(name))
                    {
                        columns.Add(new DataColumn(name, dr.GetFieldType(i)));
                    }
                }

                while (dr.Read())
                {
                    DataRow daRow = dt.NewRow();
                    for (int i = 0; i < columns.Count; i++)
                    {
                        daRow[columns[i].ColumnName] = dr.GetValue(i);
                    }
                    dt.Rows.Add(daRow);
                }
            }
        }
Example #2
0
        public void TestFunc()
        {
            DmCommand command = new DmCommand();

            command.Connection = cnn;
            try
            {
                string a, b, c;
                command.CommandText = "select * from Production.Product;";
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    a = reader.GetString(0);
                    b = reader.GetString(1);
                    c = reader.GetString(2);

                    Console.WriteLine("Nameļ¼š" + a);
                    Console.WriteLine("Author: " + b);
                    Console.WriteLine("Publisher: " + c);
                    Console.WriteLine("-----------------------------");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ret = 0;
            }
        }