Example #1
0
        public EbDataRow GetAsDataRow()
        {
            EbDataRow   row = null;
            EbDataTable dt  = new EbDataTable();

            if (Parameters != null && Parameters.Any())
            {
                row = dt.NewDataRow();
                dt.Rows.Add(row);

                List <object> dataArray = new List <object>();

                for (int i = 0; i < Parameters.Count; i++)
                {
                    EbMobileStaticParameter pm = Parameters[i];

                    dt.Columns.Add(new EbDataColumn
                    {
                        ColumnName  = pm.Name,
                        ColumnIndex = i
                    });

                    dataArray.Add(pm.Value);
                }
                row.AddRange(dataArray.ToArray());
            }
            return(row ?? dt.NewDataRow());
        }
        protected void PrepareDataTable(SqliteDataReader reader, EbDataTable dt)
        {
            try
            {
                int _fieldCount = reader.FieldCount;

                for (int i = 0; i < _fieldCount; i++)
                {
                    dt.Columns.Add(new EbDataColumn
                    {
                        ColumnName  = reader.GetName(i),
                        ColumnIndex = i,
                        Type        = DbTypeConverter.ConvertToDbType(reader.GetFieldType(i))
                    });
                }

                while (reader.Read())
                {
                    EbDataRow dr     = dt.NewDataRow();
                    object[]  oArray = new object[_fieldCount];
                    reader.GetValues(oArray);
                    dr.AddRange(oArray);
                    dt.Rows.Add(dr);
                }
            }
            catch (Exception ex)
            {
                EbLog.Error(ex.Message);
            }
        }
Example #3
0
        private void PrepareDataTable(NpgsqlDataReader reader, EbDataTable dt)
        {
            int _fieldCount = reader.FieldCount;

            while (reader.Read())
            {
                EbDataRow dr = dt.NewDataRow();
                for (int i = 0; i < _fieldCount; i++)
                {
                    var _typ = reader.GetFieldType(i);
                    if (_typ == typeof(DateTime))
                    {
                        dr[i] = reader.IsDBNull(i) ? DateTime.Now : reader.GetDateTime(i);
                        continue;
                    }
                    else if (_typ == typeof(string))
                    {
                        dr[i] = reader.IsDBNull(i) ? string.Empty : reader.GetString(i);
                        continue;
                    }
                    else if (_typ == typeof(bool))
                    {
                        dr[i] = reader.IsDBNull(i) ? false : reader.GetBoolean(i);
                        continue;
                    }
                    else if (_typ == typeof(decimal))
                    {
                        dr[i] = reader.IsDBNull(i) ? 0 : reader.GetDecimal(i);
                        continue;
                    }
                    else if (_typ == typeof(int) || _typ == typeof(Int32))
                    {
                        dr[i] = reader.IsDBNull(i) ? 0 : reader.GetInt32(i);
                        continue;
                    }
                    else if (_typ == typeof(Int64))
                    {
                        dr[i] = reader.IsDBNull(i) ? 0 : reader.GetInt64(i);
                        continue;
                    }
                    else
                    {
                        dr[i] = reader.GetValue(i);
                        continue;
                    }
                }

                dt.Rows.Add(dr);
            }
        }
        public static EbDataSet ToDataSet(this WebformData data)
        {
            EbDataSet ds = new EbDataSet();

            try
            {
                foreach (KeyValuePair <string, SingleTable> st in data.MultipleTables)
                {
                    EbDataTable dt = new EbDataTable {
                        TableName = st.Key
                    };
                    for (int i = 0; i < st.Value.Count; i++)
                    {
                        EbDataRow dr = dt.NewDataRow();
                        for (int k = 0; k < st.Value[i].Columns.Count; k++)
                        {
                            SingleColumn sc = st.Value[i].Columns[k];

                            if (i == 0)
                            {
                                EbDataColumn dc = new EbDataColumn
                                {
                                    ColumnIndex = k,
                                    Type        = (EbDbTypes)sc.Type,
                                    ColumnName  = sc.Name
                                };
                                dt.Columns.Add(dc);
                            }
                            dr.Add((object)sc.Value);
                        }
                        dt.Rows.Add(dr);
                    }
                    ds.Tables.Add(dt);
                }
            }
            catch (Exception ex)
            {
                EbLog.Info("WebformData to dataset operation failed");
                EbLog.Error(ex.StackTrace);
            }
            return(ds);
        }