本文整理汇总了C#中IDataReader.GetDataTypeName方法的典型用法代码示例。如果您正苦于以下问题:C# IDataReader.GetDataTypeName方法的具体用法?C# IDataReader.GetDataTypeName怎么用?C# IDataReader.GetDataTypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataReader
的用法示例。
在下文中一共展示了IDataReader.GetDataTypeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CGIResponseData
public CGIResponseData(IDataReader reader)
{
Captions = new string[reader.FieldCount];
DataTypes = new string[reader.FieldCount];
for (var ordinal = 0; ordinal < Captions.Length; ordinal++)
{
Captions[ordinal] = reader.GetName(ordinal);
DataTypes[ordinal] = reader.GetDataTypeName(ordinal);
}
var rows = new List<string[]>(1000);
while (reader.Read())
{
var row = new string[Captions.Length];
for (var ordinal = 0; ordinal < Captions.Length; ordinal++)
{
if (reader.IsDBNull(ordinal))
{
row[ordinal] = null;
}
else
{
var value = reader.GetValue(ordinal);
row[ordinal] = value == null ? null : value.ToString();
}
}
rows.Add(row);
}
Values = rows.ToArray();
}
示例2: CreateFormatString
private static string CreateFormatString(IDataReader reader)
{
int maxFieldNameLen = 0;
int maxDbTypeNameLen = 0;
for (var i = 0; i < reader.FieldCount; i++)
{
maxFieldNameLen = Math.Max(maxFieldNameLen, reader.GetName(i).Length);
maxDbTypeNameLen = Math.Max(maxDbTypeNameLen, reader.GetDataTypeName(i).Length);
}
return string.Format("{{0,3}} - {{1,{0}}} - {{2,{1}}}: ", maxFieldNameLen, maxDbTypeNameLen);
}
示例3: DataReaderResult
/// <summary>
/// Initializes a new instance of the <see cref="DataReaderResult"/> class.
/// </summary>
public DataReaderResult(IDataReader reader)
{
try
{
_data = ReadAll(reader).ToArray();
_schema = new DataReaderField[reader.FieldCount];
for (int i = 0; i < reader.FieldCount; i++)
{
_schema[i] = new DataReaderField(reader.GetName(i), reader.GetFieldType(i),
reader.GetDataTypeName(i));
}
}
finally
{
reader.Close();
reader.Dispose();
}
}
示例4: DisconnectedReader
/// <summary>
/// Caches a data reader to enable disconnected data access via the IDataReader interface.
/// </summary>
/// <param name="reader">The IDataReader to cache.</param>
public DisconnectedReader(IDataReader reader)
{
// Cache field information
this.fields = new FieldInfo[reader.FieldCount];
this.ordinals = new Hashtable(StringComparer.OrdinalIgnoreCase);
for (int index = 0; index < fields.Length; index++)
{
FieldInfo field = new FieldInfo();
field.Name = reader.GetName(index);
field.Type = reader.GetFieldType(index);
field.DataTypeName = reader.GetDataTypeName(index);
fields[index] = field;
if (!ordinals.Contains(field.Name))
ordinals.Add(field.Name, index);
}
// Cache schema info
schema = reader.GetSchemaTable();
// Cache row data
rows = new ArrayList();
while (reader.Read())
{
object[] values = new object[fields.Length];
reader.GetValues(values);
rows.Add(values);
}
// Cache additional results
if (reader.NextResult())
nextResult = new DisconnectedReader(reader);
// Close the reader once all data has been cached
else
reader.Dispose();
// Set the record index before the first record;
this.recordIndex = -1;
this.lastIndex = rows.Count - 1;
}
示例5: HtmlTable
public static HtmlTable HtmlTable(IDataReader rd)
{
var t = new HtmlTable();
t.Attributes.Add("class", "table table-striped");
var h = new HtmlTableRow();
for (var i = 0; i < rd.FieldCount; i++)
{
var typ = rd.GetDataTypeName(i);
var nam = rd.GetName(i).ToLower();
string align = null;
switch (typ.ToLower())
{
case "decimal":
align = "right";
break;
case "int":
if (!nam.EndsWith("id") && !nam.EndsWith("id2"))
align = "right";
break;
}
h.Cells.Add(new HtmlTableCell
{
InnerText = rd.GetName(i),
Align = align
});
}
t.Rows.Add(h);
while (rd.Read())
{
var r = new HtmlTableRow();
for (var i = 0; i < rd.FieldCount; i++)
{
var typ = rd.GetDataTypeName(i);
var nam = rd.GetName(i).ToLower();
string s;
string align = null;
switch (typ.ToLower())
{
case "decimal":
s = Convert.ToDecimal(rd[i]).ToString("c");
align = "right";
break;
case "int":
if (nam.EndsWith("id") || nam.EndsWith("id2"))
s = rd[i].ToInt().ToString();
else
{
s = rd[i].ToInt().ToString("N0");
align = "right";
}
break;
default:
s = rd[i].ToString();
break;
}
r.Cells.Add(new HtmlTableCell()
{
InnerHtml = s,
Align = align
});
}
t.Rows.Add(r);
}
var tc = new HtmlTableCell
{
ColSpan = rd.FieldCount,
InnerText = $"Count = {t.Rows.Count - 1} rows"
};
var tr = new HtmlTableRow();
tr.Cells.Add(tc);
t.Rows.Add(tr);
return t;
}
示例6: SetEditViewFields
//.........这里部分代码省略.........
txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]);
}
catch(Exception ex)
{
SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
txtNAME.Text = ex.Message;
}
HtmlInputHidden hidID = Parent.FindControl(sDATA_FIELD) as HtmlInputHidden;
if ( hidID != null )
{
try
{
hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
}
catch(Exception ex)
{
SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
txtNAME.Text = ex.Message;
}
}
}
}
}
else if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 || String.Compare(sFIELD_TYPE, "Password", true) == 0 )
{
if ( !Sql.IsEmptyString(sDATA_FIELD) )
{
TextBox txtField = Parent.FindControl(sDATA_FIELD) as TextBox;
if ( txtField != null )
{
try
{
int nOrdinal = rdr.GetOrdinal(sDATA_FIELD);
string sTypeName = rdr.GetDataTypeName(nOrdinal);
if ( sTypeName == "money" || rdr[sDATA_FIELD].GetType() == typeof(System.Decimal) )
txtField.Text = Sql.ToDecimal(rdr[sDATA_FIELD]).ToString("#,##0.00");
else
txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
}
catch(Exception ex)
{
SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
txtField.Text = ex.Message;
}
}
}
}
// 04/02/2009 Add support for FCKEditor to the EditView.
else if ( String.Compare(sFIELD_TYPE, "HtmlEditor", true) == 0 )
{
if ( !Sql.IsEmptyString(sDATA_FIELD) )
{
// 09/18/2011 Upgrade to CKEditor 3.6.2.
CKEditorControl txtField = Parent.FindControl(sDATA_FIELD) as CKEditorControl;
if ( txtField != null )
{
try
{
txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
}
catch(Exception ex)
{
SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
txtField.Text = ex.Message;
}
}
示例7: Retrieve
public void Retrieve(IDataReader reader)
{
bool isColumnsEmpty = true;
WidgetCollection rows = this["rows"] as WidgetCollection;
while (reader.Read())
{
if (isColumnsEmpty)
{
isColumnsEmpty = false;
for (int i = 0; i < reader.FieldCount; i++)
{
string field = reader.GetName(i);
string type = reader.GetFieldType(i).Name;
string dtype = reader.GetDataTypeName(i);
WidgetCollection list = this["cols"] as WidgetCollection;
if (list != null)
{
Widget col = new Widget();
col["field"] = field;
col["caption"] = field;
col["type"] = type;
col["datatype"] = dtype;
list.Add(col);
}
}
}
if (rows != null)
{
Widget row = new Widget();
for (int i = 0; i < reader.FieldCount; i++)
{
string field = reader.GetName(i);
row[field] = reader.GetValue(i);
}
rows.Add(row);
}
}
}
示例8: AppendEditViewFields
//.........这里部分代码省略.........
}
}
}
else if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 || String.Compare(sFIELD_TYPE, "Password", true) == 0 )
{
if ( !Sql.IsEmptyString(sDATA_FIELD) )
{
TextBox txtField = new TextBox();
tdField.Controls.Add(txtField);
txtField.ID = sDATA_FIELD;
txtField.TabIndex = nFORMAT_TAB_INDEX;
try
{
if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 )
{
txtField.Rows = nFORMAT_ROWS ;
txtField.Columns = nFORMAT_COLUMNS;
txtField.TextMode = TextBoxMode.MultiLine;
}
else
{
txtField.MaxLength = nFORMAT_MAX_LENGTH ;
txtField.Attributes.Add("size", nFORMAT_SIZE.ToString());
txtField.TextMode = TextBoxMode.SingleLine;
}
if ( bLayoutMode )
{
txtField.Text = sDATA_FIELD;
txtField.ReadOnly = true ;
}
else if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
{
int nOrdinal = rdr.GetOrdinal(sDATA_FIELD);
string sTypeName = rdr.GetDataTypeName(nOrdinal);
// 03/04/2006 Paul. Display currency in the proper format.
// Only SQL Server is likely to return the money type, so also include the decimal type.
if ( sTypeName == "money" || rdr[sDATA_FIELD].GetType() == typeof(System.Decimal) )
txtField.Text = Sql.ToDecimal(rdr[sDATA_FIELD]).ToString("#,##0.00");
else
txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
}
}
catch(Exception ex)
{
SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
txtField.Text = ex.Message;
}
if ( String.Compare(sFIELD_TYPE, "Password", true) == 0 )
txtField.TextMode = TextBoxMode.Password;
if ( !bLayoutMode && bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
{
RequiredFieldValidator reqNAME = new RequiredFieldValidator();
reqNAME.ID = sDATA_FIELD + "_REQUIRED";
reqNAME.ControlToValidate = txtField.ID;
reqNAME.ErrorMessage = L10n.Term(".ERR_REQUIRED_FIELD");
reqNAME.CssClass = "required";
reqNAME.EnableViewState = false;
// 01/16/2006 Paul. We don't enable required fields until we attempt to save.
// This is to allow unrelated form actions; the Cancel button is a good example.
reqNAME.EnableClientScript = false;
reqNAME.Enabled = false;
tdField.Controls.Add(reqNAME);
}
}
}
else if ( String.Compare(sFIELD_TYPE, "DatePicker", true) == 0 )
示例9: Fetch_Assoc
private static PhpArray Fetch_Assoc(PDODriver driver, IDataReader dr, bool withNum)
{
if (dr.Read())
{
int fieldCount = dr.FieldCount;
PhpArray arr = new PhpArray(fieldCount * (withNum ? 2 : 1));
for (int i = 0; i < fieldCount; i++)
{
string fName = dr.GetName(i);
object value = driver.ConvertDbValue(dr.GetValue(i), dr.GetDataTypeName(i));
arr.Add(fName, value);
if (withNum)
arr.Add(i, value);
}
return arr;
}
else
{
return null;
}
}
示例10: GetObjectFromDatabase
private Object GetObjectFromDatabase(IDataReader reader, int columnNum)
{
object value = null;
if (reader.GetName(columnNum) == GetDataLink().PrimaryKey)
{
// it's the object's guidfield
value = reader.GetGuid(columnNum);
}
else
{
switch (reader.GetDataTypeName(columnNum).ToLower())
{
case ("nchar"):
case ("char"):
// fixed length char columns need to be trimmed
value = reader.GetString(columnNum).Trim();
break;
case ("nvarchar"):
case ("varchar"):
case ("text"):
case ("ntext"):
value = reader.GetString(columnNum);
break;
case "tinyint":
value = reader.GetByte(columnNum);
break;
case "smallint":
value = reader.GetInt16(columnNum);
break;
case "int":
value = reader.GetInt32(columnNum);
break;
case "bit":
value = reader.GetBoolean(columnNum);
break;
case "smalldatetime":
case "datetime":
value = reader.GetDateTime(columnNum);
break;
case "money":
value = reader.GetDecimal(columnNum);
break;
case "bigint":
value = reader.GetInt64(columnNum);
break;
case "uniqueidentifier":
value = reader.GetGuid(columnNum);
break;
case "decimal":
value = reader.GetDecimal(columnNum);
break;
default:
throw new ApplicationException(string.Format("Unknown conversion for {0} data type.", reader.GetDataTypeName(columnNum)));
}
}
return value;
}
示例11: HtmlTable
public static HtmlTable HtmlTable(IDataReader rd)
{
var pctnames = new List<string> {"pct", "percent"};
var t = new HtmlTable();
t.Attributes.Add("class", "table table-striped");
var h = new HtmlTableRow();
for (var i = 0; i < rd.FieldCount; i++)
{
var typ = rd.GetDataTypeName(i);
var nam = rd.GetName(i).ToLower();
string align = null;
switch (typ.ToLower())
{
case "decimal":
align = "right";
break;
case "int":
if (!nam.EndsWith("id") && !nam.EndsWith("id2"))
align = "right";
break;
}
h.Cells.Add(new HtmlTableCell
{
InnerText = rd.GetName(i),
Align = align
});
}
t.Rows.Add(h);
while (rd.Read())
{
var r = new HtmlTableRow();
for (var i = 0; i < rd.FieldCount; i++)
{
var typ = rd.GetDataTypeName(i);
var nam = rd.GetName(i).ToLower();
string s;
string align = null;
switch (typ.ToLower())
{
case "decimal":
s = StartsEndsWith(pctnames, nam)
? Convert.ToDecimal(rd[i]).ToString("N1") + "%"
: Convert.ToDecimal(rd[i]).ToString("c");
align = "right";
break;
case "float":
s = StartsEndsWith(pctnames, nam)
? Convert.ToDouble(rd[i]).ToString("N1") + "%"
: Convert.ToDouble(rd[i]).ToString("N1");
align = "right";
break;
case "int":
var ii = rd[i].ToInt();
if (nam.Equal("peopleid"))
s = $"<a href='/Person2/{ii}' target='Person'>{ii}</a>";
else if (nam.Equal("organizationid"))
s = $"<a href='/Org/{ii}' target='Organization'>{ii}</a>";
else if (nam.EndsWith("id") || nam.EndsWith("id2"))
s = rd[i].ToInt().ToString();
else
{
s = rd[i].ToInt().ToString("N0");
align = "right";
}
break;
default:
s = rd[i].ToString();
break;
}
r.Cells.Add(new HtmlTableCell()
{
InnerHtml = s,
Align = align
});
}
t.Rows.Add(r);
}
var tc = new HtmlTableCell
{
ColSpan = rd.FieldCount,
InnerText = $"Count = {t.Rows.Count - 1} rows"
};
var tr = new HtmlTableRow();
tr.Cells.Add(tc);
t.Rows.Add(tr);
return t;
}
示例12: ShowStructure
/// <summary>Hiển thị lưới kiểu dữ liệu C# và DBType
/// Dùng để kiểm tra xem
/// </summary>
public static void ShowStructure(IDataReader IDReader, string Msg)
{
bool IsDebug = FrameworkParams.isSupportDeveloper;
if (IsDebug)
{
frmGridInfo frm = new frmGridInfo();
DataSet ds = new DataSet();
DataTable table = new DataTable("reader");
table.Columns.Add("ID", System.Type.GetType("System.String"));
table.Columns.Add("Name", System.Type.GetType("System.String"));
table.Columns.Add("DBType", System.Type.GetType("System.String"));
table.Columns.Add("C#Type", System.Type.GetType("System.String"));
table.Columns.Add("Value", System.Type.GetType("System.String"));
ds.Tables.Add(table);
int j = 1;
while (IDReader.Read())
{
for (int i = 0; i < IDReader.FieldCount; i++)
{
object[] row = {
j.ToString() + "." + i.ToString(),
IDReader.GetName(i),
IDReader.GetDataTypeName(i),
IDReader.GetValue(i).GetType().ToString(),
IDReader.GetValue(i).ToString()
};
ds.Tables[0].Rows.Add(row);
}
//BLANK ROW
object[] blankrow = {
"-----",
"-----",
"-----",
"-----",
"-----"
};
ds.Tables[0].Rows.Add(blankrow);
j++;
}
IDReader.Close();
frm.InitData(ds, Msg);
//frm.TopMost = true;
frm.TopLevel = true;
ProtocolForm.ShowDialog(FrameworkParams.MainForm, frm);
}
}
示例13: HtmlTable
public static Table HtmlTable(IDataReader rd, string title = null, int? maxrows = null)
{
var pctnames = new List<string> {"pct", "percent"};
var t = new Table();
t.Attributes.Add("class", "table table-striped");
if (title.HasValue())
{
var c = new TableHeaderCell
{
ColumnSpan = rd.FieldCount,
Text = title,
};
c.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
var r = new TableHeaderRow {TableSection = TableRowSection.TableHeader};
r.Cells.Add(c);
t.Rows.Add(r);
}
var h = new TableHeaderRow {TableSection = TableRowSection.TableHeader};
for (var i = 0; i < rd.FieldCount; i++)
{
var typ = rd.GetDataTypeName(i);
var nam = rd.GetName(i).ToLower();
var align = HorizontalAlign.NotSet;
switch (typ.ToLower())
{
case "decimal":
align = HorizontalAlign.Right;
break;
case "int":
if (nam != "Year" && !nam.EndsWith("id") && !nam.EndsWith("id2"))
align = HorizontalAlign.Right;
break;
}
h.Cells.Add(new TableHeaderCell
{
Text = rd.GetName(i),
HorizontalAlign = align
});
}
t.Rows.Add(h);
var rn = 0;
while (rd.Read())
{
rn++;
if (maxrows.HasValue && rn > maxrows)
break;
var r = new TableRow();
for (var i = 0; i < rd.FieldCount; i++)
{
var typ = rd.GetDataTypeName(i);
var nam = rd.GetName(i).ToLower();
string s;
var align = HorizontalAlign.NotSet;
switch (typ.ToLower())
{
case "decimal":
var dec = rd[i].ToNullableDecimal();
s = StartsEndsWith(pctnames, nam)
? dec.ToString2("N1", "%")
: dec.ToString2("c");
align = HorizontalAlign.Right;
break;
case "real":
case "float":
var dbl = rd[i].ToNullableDouble();
s = StartsEndsWith(pctnames, nam)
? dbl.ToString2("N1", "%")
: dbl.ToString2("N1");
align = HorizontalAlign.Right;
break;
case "date":
case "datetime":
var dt = rd[i].ToNullableDate();
if (dt.HasValue && dt.Value.Date != dt.Value)
s = dt.FormatDateTime();
else
s = dt.FormatDate();
break;
case "int":
var ii = rd[i].ToNullableInt();
if (nam.Equal("peopleid") || nam.Equal("spouseid"))
s = $"<a href='/Person2/{ii}' target='Person'>{ii}</a>";
else if (nam.Equal("organizationid") || nam.EndsWith("orgid"))
s = $"<a href='/Org/{ii}' target='Organization'>{ii}</a>";
else if (nam.EndsWith("id") || nam.EndsWith("id2") || nam.Equal("Year"))
s = ii.ToString();
else
{
s = ii.ToString2("N0");
align = HorizontalAlign.Right;
}
break;
default:
s = rd[i].ToString();
if (s == "Total")
s = $"<strong>{s}</strong>";
break;
}
r.Cells.Add(new TableCell()
//.........这里部分代码省略.........
示例14: AppendErrorMsg
public static string AppendErrorMsg(IDataReader reader, int ordinal)
{
string msg = string.Format("Error: {0}({1},{2},{3})", reader.GetName(ordinal), ordinal.ToString(), reader.GetDataTypeName(ordinal), reader.GetFieldType(ordinal).FullName);
return msg;
}
示例15: DbUsesStrings
// YUCK
static internal bool DbUsesStrings (IDataReader r, int whichcol) {
if (db_uses_strings == -1) {
string dn = r.GetDataTypeName (whichcol);
if (dn == "string" || dn == "System.String" || dn == "text") {
Console.WriteLine ("*** Database uses strings for all data types");
db_uses_strings = 1;
return true;
} else {
Console.WriteLine ("*** Database does NOT use strings for all data types (type is " + dn + ")");
db_uses_strings = 0;
return false;
}
}
return (db_uses_strings == 1);
}