本文整理汇总了C#中System.Data.SqlClient.SqlDataReader.GetName方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataReader.GetName方法的具体用法?C# SqlDataReader.GetName怎么用?C# SqlDataReader.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlDataReader
的用法示例。
在下文中一共展示了SqlDataReader.GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: toJSON
private static string toJSON(SqlDataReader rdr)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
JsonWriter jsonWriter = new JsonTextWriter(sw);
jsonWriter.WriteStartArray();
while (rdr.Read())
{
int fieldcount = rdr.FieldCount; // count how many columns are in the row
object[] values = new object[fieldcount]; // storage for column values
rdr.GetValues(values); // extract the values in each column
jsonWriter.WriteStartObject();
for (int index = 0; index < fieldcount; index++)
{
string colName = rdr.GetName(index);
object value = values[index];
jsonWriter.WritePropertyName(colName);
if (value == DBNull.Value)
value = "";
else if (colName.Contains("date") && !colName.Contains("by"))
value = String.Format("{0:MM/dd/yyyy HH:mm tt}", value);
jsonWriter.WriteValue(value);
}
jsonWriter.WriteEndObject();
}
jsonWriter.WriteEndArray();
return sb.ToString();
}
示例2: Read
public static PMSAgency Read(SqlDataReader reader)
{
PMSAgency retval = new PMSAgency();
for (int i = 0; i < reader.FieldCount; i++)
{
switch (reader.GetName(i))
{
case "GroupSegment":
retval.Segment = Helper.ToString(reader[i]);
break;
case "AType":
retval.ActionType = Helper.ToString(reader[i]);
break;
case "Agency":
retval.AgencyName = Helper.ToString(reader[i]);
break;
case "Market":
retval.Market = Helper.ToString(reader[i]);
break;
case "RepGroup":
retval.RepGroup = Helper.ToString(reader[i]);
break;
case "SiteID":
retval.SiteID = Helper.ToInt32(reader[i]);
break;
}
}
return retval;
}
示例3: JSOMembers
private static string[] JSOMembers(SqlDataReader sdr, bool camelCase)
{
string[] names = new string[sdr.FieldCount];
for (int i = 0; i < sdr.FieldCount; i++)
{
names[i] = (camelCase ? sdr.GetName(i).ToCamelCase() : sdr.GetName(i));
}
return names;
}
示例4: GetPK
public static Tuple<int, string> GetPK(SqlDataReader model)
{
for (int i = 0; i < model.FieldCount; i++)
{
if (model.GetName(i).EndsWith("id", StringComparison.InvariantCultureIgnoreCase))
{
return new Tuple<int, string>(i, model.GetName(i));
}
}
return null;
}
示例5: Coluna
/// <summary>
/// Verifica se o campo está explícito na instrução Sql
/// </summary>
/// <param name="oDr">DataReader</param>
/// <param name="Campo">Nome do Campo</param>
/// <returns></returns>
public bool Coluna(SqlDataReader oDr, string Campo)
{
for (int i = 0; i < oDr.FieldCount; i++)
{
string nome = oDr.GetName(i);
if (oDr.GetName(i) == Campo)
return true;
}
return false;
}
示例6: Model
public Model(SqlDataReader reader)
: this()
{
for (int i = 0; i < reader.FieldCount; i++)
{
PropertyInfo property = this.GetType().GetProperty(reader.GetName(i));
if (property != null)
{
property.SetValue(this, reader[reader.GetName(i)] == System.DBNull.Value ? null : reader[reader.GetName(i)]);
}
}
}
示例7: SqlDataReader2Json
public static JArray SqlDataReader2Json(SqlDataReader reader, string col0, string col1)
{
var colNames = new Dictionary<string, int>();
for (int i = 0; i < reader.FieldCount; i++)
{
colNames[reader.GetName(i)] = i;
}
var parent = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase);
while (reader.Read())
{
string parentColumn = reader.GetString(colNames[col0]);
string childColumn = reader.GetString(colNames[col1]);
HashSet<string> child;
if (!parent.TryGetValue(parentColumn, out child))
{
child = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
parent.Add(parentColumn, child);
}
child.Add(childColumn);
}
return MakeJArray(parent);
}
示例8: ColumnExists
public static bool ColumnExists(SqlDataReader dataReader, string columnName)
{
for (Int32 iCol = 0; iCol < dataReader.FieldCount; iCol++)
if (columnName.ToUpper().Equals(dataReader.GetName(iCol).ToUpper()))
return true;
return false;
}
示例9: WebSqlCommandResult
public WebSqlCommandResult(SqlDataReader reader)
{
this.rows = new List<List<string>>(reader.RecordsAffected + 1);
this.rowsAffected = reader.RecordsAffected;
int fieldCount = reader.FieldCount;
this.columns = new List<string>(fieldCount);
int internalRowCount = 0;
for (int i = 0; i < fieldCount; i++)
{
this.columns.Add(reader.GetName(i));
}
while (reader.Read())
{
var columns = new List<string>(fieldCount);
for (int i = 0; i < fieldCount; i++)
{
columns.Add(reader[i].ToString());
}
rows.Add(columns);
internalRowCount++;
}
if (this.rowsAffected == -1 && internalRowCount > 0)
{
this.rowsAffected = internalRowCount;
}
this.errorCode = 0;
this.errorLineNumber = 0;
this.errorMessage = "";
}
示例10: Read
public static SIHOT_Package Read(SqlDataReader reader)
{
SIHOT_Package retval = new SIHOT_Package();
for (int i = 0; i < reader.FieldCount; i++)
{
switch (reader.GetName(i))
{
case "PCIID":
retval.PCIID = Helper.ToInt32(reader[i]);
break;
case "FROM_PACKAGE":
retval.SIHOT_PACKAGE_FROM = Helper.ToDateTime(reader[i]);
break;
case "TO_PACKAGE":
retval.SIHOT_PACKAGE_TO = Helper.ToDateTime(reader[i]);
break;
case "SID":
retval.SIHOT_PACKAGE_SID = Helper.ToString(reader[i]);
break;
case "RS":
retval.SIHOT_PACKAGE_RS = Helper.ToString(reader[i]);
break;
case "SIDT":
retval.SIHOT_PACKAGE_SIDT = Helper.ToString(reader[i]);
break;
}
}
return retval;
}
示例11: CreateDocument
static Document CreateDocument(SqlDataReader reader, IDictionary<int, List<string>> packageFrameworks)
{
var package = new Dictionary<string, string>();
for (var i = 0; i < reader.FieldCount; i++)
{
if (!reader.IsDBNull(i))
{
string name = reader.GetName(i);
object obj = reader.GetValue(i);
if (name == "key")
{
var key = (int)obj;
List<string> targetFrameworks;
if (packageFrameworks.TryGetValue(key, out targetFrameworks))
{
package.Add("supportedFrameworks", string.Join("|", targetFrameworks));
}
}
var value = (obj is DateTime) ? ((DateTime)obj).ToUniversalTime().ToString("O") : obj.ToString();
package.Add(name, value);
}
}
return DocumentCreator.CreateDocument(package);
}
示例12: LireSQL
private StringBuilder LireSQL(SqlDataReader dataR1)
{
StringBuilder BLD = new StringBuilder();
BLD.Append("<table style='background-color: #0066ff; color: white; width: 100%' class='tabProduits'><tr>");
for (int i = 0; i < dataR1.FieldCount; i++)
{
BLD.Append("<th style='background-color: black'>" + dataR1.GetName(i) + "</th>");
}
BLD.Append("<tr>");
while (dataR1.Read())
{
BLD.Append("<tr>");
for (int i = 0; i < dataR1.FieldCount; i++)
{
BLD.Append("<th>" + dataR1[i] + "</th>");
}
BLD.Append("</tr>");
}
BLD.Append("</table>");
return BLD;
}
示例13: Convertdrtodt
/// <summary>
/// SqlDataReaderתDataTableTable
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public static DataTable Convertdrtodt(SqlDataReader dr, DataTable dataTable)
{
//DataTable dataTable = new DataTable();//��һ���µ�ʵ��
for (int i = 0; i < dr.FieldCount; i++)
{
DataColumn mydc = new DataColumn();//�ؼ���һ��
mydc.DataType = dr.GetFieldType(i);
mydc.ColumnName = dr.GetName(i);
dataTable.Columns.Add(mydc);//�ؼ��ĵڶ���
}
while (dr.Read())
{
DataRow mydr = dataTable.NewRow();//�ؼ��ĵ�����
for (int i = 0; i < dr.FieldCount; i++)
{
mydr[i] = dr[i];//.ToString();
}
dataTable.Rows.Add(mydr);//�ؼ��ĵ��IJ�
mydr = null;
}
dr.Close();
return (dataTable);//������Ҫ����datatable���������
}
示例14: ConvertdrTodt
/// <summary>
/// 将DataReader转为DataTable
/// </summary>
/// <param name="DataReader">DataReader</param>
public static DataTable ConvertdrTodt(SqlDataReader dataReader)
{
///定义DataTable
DataTable datatable = new DataTable();
///动态添加表的数据列
for (int i = 0; i < dataReader.FieldCount; i++)
{
DataColumn mydc = new DataColumn();
mydc.DataType = dataReader.GetFieldType(i);
mydc.ColumnName = dataReader.GetName(i);
datatable.Columns.Add(mydc);
}
///添加表的数据
while (dataReader.Read())
{
DataRow mydr = datatable.NewRow();
for (int i = 0; i < dataReader.FieldCount; i++)
{
mydr[i] = dataReader[i].ToString();
}
datatable.Rows.Add(mydr);
mydr = null;
}
///关闭数据读取器
dataReader.Close();
return datatable;
}
示例15: DisplayQueryResultHeader
private static void DisplayQueryResultHeader(SqlDataReader queryResult)
{
for (int i = 0; i < queryResult.FieldCount; i++)
{
Console.Write("{0}\t", queryResult.GetName(i));
}
Console.WriteLine();
}