本文整理汇总了C#中System.Data.SqlClient.SqlDataReader类的典型用法代码示例。如果您正苦于以下问题:C# SqlDataReader类的具体用法?C# SqlDataReader怎么用?C# SqlDataReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlDataReader类属于System.Data.SqlClient命名空间,在下文中一共展示了SqlDataReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: convert
public List<List<String>> convert(SqlDataReader reader)
{
if (reader != null)
{
List<List<String>> list = new List<List<String>>();
while (reader.Read())
{
List<String> tmp = new List<String>();
for (int i = 0; i < reader.FieldCount; i++)
{
string s = "";
try
{
s = reader.GetString(i);
}
catch (SqlNullValueException)
{
s = "null";
}
tmp.Add(s);
}
list.Add(tmp);
}
return list;
}
return null;
}
示例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: SafeGetString
/** Descripcion:
*
* REQ: SqlDataReader, int
*
* RET: static string
*/
public static string SafeGetString(SqlDataReader reader, int colIndex)
{
if (!reader.IsDBNull(colIndex))
return reader.GetString(colIndex);
else
return string.Empty;
}
示例4: HashSum
public HashSum(SqlDataReader reader, String secret = "PZS")
{
DataTable dt = new DataTable();
dt.Load(reader);
dt.TableName = secret;
this.dt = dt;
}
示例5: CloseCommand
public bool CloseCommand()
{
bool flag = true;
try
{
if (connection != null)
{
if (sqlReader != null)
{
sqlReader.Close();
sqlReader.Dispose();
sqlReader = (SqlDataReader)null;
}
if (sqlCommand != null)
{
sqlCommand.Dispose();
sqlCommand = (SqlCommand)null;
}
}
}
catch (Exception ex)
{
flag = false;
hasError = true;
errorMessage = "Database command error : " + ex.Message;
}
return flag;
}
示例6: SqlCachedBuffer
internal SqlCachedBuffer(SqlDataReader dataRdr, int columnOrdinal, long startPosition)
{
int num;
this._cachedBytes = new ArrayList();
long dataIndex = startPosition;
do
{
byte[] buffer = new byte[0x800];
num = (int) dataRdr.GetBytesInternal(columnOrdinal, dataIndex, buffer, 0, 0x800);
dataIndex += num;
if (this._cachedBytes.Count == 0)
{
this.AddByteOrderMark(buffer, num);
}
if (0 < num)
{
if (num < buffer.Length)
{
byte[] dst = new byte[num];
Buffer.BlockCopy(buffer, 0, dst, 0, num);
buffer = dst;
}
this._cachedBytes.Add(buffer);
}
}
while (0 < num);
}
示例7: LoadFromDataReader
/// <summary>
/// Loads the entity from a <b>SqlDataReader</b> object.
/// </summary>
/// <param name="dr">The data reader to read from.</param>
/// <returns>Returns the number of columns read.</returns>
/// <remarks>
/// Always reads at the current cursor position, doesn't calls the <b>Read</b> function
/// on the <b>SqlDataReader</b> object. Reads data columns by their ordinal position in
/// the query and not by their names.
/// </remarks>
internal override int LoadFromDataReader(SqlDataReader dr)
{
int o = base.LoadFromDataReader(dr);
++o; // skip guid
this.workflowTypeName = dr.GetString(++o);
this.dateStarted = dr.IsDBNull(++o) ? DateTime.MinValue : dr.GetDateTime(o);
this.dateFinished = dr.IsDBNull(++o) ? DateTime.MinValue : dr.GetDateTime(o);
this.jobExecutionStatus = (JobExecutionState)dr.GetInt32(++o);
this.suspendTimeout = dr.IsDBNull(++o) ? DateTime.MinValue : dr.GetDateTime(o);
this.scheduleType = (ScheduleType)dr.GetInt32(++o);
this.scheduleTime = dr.IsDBNull(++o) ? DateTime.MinValue : dr.GetDateTime(o);
this.recurringPeriod = (RecurringPeriod)dr.GetInt32(++o);
this.recurringInterval = dr.GetInt32(++o);
this.recurringMask = dr.GetInt64(++o);
this.workflowInstanceId = dr.IsDBNull(++o) ? Guid.Empty : dr.GetGuid(o);
this.adminRequestTime = dr.IsDBNull(++o) ? DateTime.MinValue : dr.GetDateTime(o);
if (!dr.IsDBNull(++o))
{
XmlSerializer ser = new XmlSerializer(typeof(JobAdminRequestData));
StringReader sr = new StringReader(dr.GetString(o));
this.adminRequestData = (JobAdminRequestData)ser.Deserialize(sr);
}
else
{
this.adminRequestData = null;
}
this.adminRequestResult = dr.GetInt32(++o);
this.exceptionMessage = dr.IsDBNull(++o) ? null : dr.GetString(o);
return o;
}
示例8: ChiTietPhieuXuatKho
public ChiTietPhieuXuatKho(SqlDataReader dataReader)
{
PhieuXuatKhoGuid = dataReader["PhieuXuatKhoGuid"] != null ? (Guid)dataReader["PhieuXuatKhoGuid"] : Guid.Empty;
ItemStoreGuid = dataReader["ItemStoreGuid"] != null ? (Guid)dataReader["ItemStoreGuid"] : Guid.Empty;
HoaDonBanHangGuid = dataReader["HoaDonBanHangGuid"] != null ? (Guid)dataReader["HoaDonBanHangGuid"] : Guid.Empty;
SoLuong = dataReader["SoLuong"] != null ? (Int32)dataReader["SoLuong"] : 0;
}
示例9: MakeViewAuditoriaListaVerificacionDetalleCross
/// <summary>
/// Creates a new instance of the ViewAuditoriaListaVerificacionDetalleCross class and populates it with data from the specified SqlDataReader.
/// </summary>
private static ViewAuditoriaListaVerificacionDetalleCrossInfo MakeViewAuditoriaListaVerificacionDetalleCross(SqlDataReader dataReader)
{
ViewAuditoriaListaVerificacionDetalleCrossInfo viewAuditoriaListaVerificacionDetalleCross = new ViewAuditoriaListaVerificacionDetalleCrossInfo();
if (dataReader.IsDBNull(AuditoriaListaVerificacionDetalleCargoId) == false)
viewAuditoriaListaVerificacionDetalleCross.AuditoriaListaVerificacionDetalleCargoId = dataReader.GetInt32(AuditoriaListaVerificacionDetalleCargoId);
if (dataReader.IsDBNull(AuditoriaListaVerificacionDetalleId) == false)
viewAuditoriaListaVerificacionDetalleCross.AuditoriaListaVerificacionDetalleId = dataReader.GetInt32(AuditoriaListaVerificacionDetalleId);
if (dataReader.IsDBNull(AuditoriaListaVerificacionId) == false)
viewAuditoriaListaVerificacionDetalleCross.AuditoriaListaVerificacionId = dataReader.GetInt32(AuditoriaListaVerificacionId);
if (dataReader.IsDBNull(CargoId) == false)
viewAuditoriaListaVerificacionDetalleCross.CargoId = dataReader.GetInt32(CargoId);
if (dataReader.IsDBNull(Cargo) == false)
viewAuditoriaListaVerificacionDetalleCross.Cargo = dataReader.GetString(Cargo);
if (dataReader.IsDBNull(Activo) == false)
viewAuditoriaListaVerificacionDetalleCross.Activo = dataReader.GetBoolean(Activo);
if (dataReader.IsDBNull(AuditoriaPunto) == false)
viewAuditoriaListaVerificacionDetalleCross.AuditoriaPunto = dataReader.GetString(AuditoriaPunto);
if (dataReader.IsDBNull(AuditoriaControl) == false)
viewAuditoriaListaVerificacionDetalleCross.AuditoriaControl = dataReader.GetString(AuditoriaControl);
if (dataReader.IsDBNull(PuntajeRequerido) == false)
viewAuditoriaListaVerificacionDetalleCross.PuntajeRequerido = dataReader.GetDecimal(PuntajeRequerido);
if (dataReader.IsDBNull(Empresa) == false)
viewAuditoriaListaVerificacionDetalleCross.Empresa = dataReader.GetString(Empresa);
if (dataReader.IsDBNull(Orden) == false)
viewAuditoriaListaVerificacionDetalleCross.Orden = dataReader.GetByte(Orden);
return viewAuditoriaListaVerificacionDetalleCross;
}
示例10: MakeViewSeguridadUsuario
/// <summary>
/// Creates a new instance of the ViewSeguridadUsuario class and populates it with data from the specified SqlDataReader.
/// </summary>
private static ViewSeguridadUsuarioInfo MakeViewSeguridadUsuario(SqlDataReader dataReader)
{
ViewSeguridadUsuarioInfo viewSeguridadUsuario = new ViewSeguridadUsuarioInfo();
if (dataReader.IsDBNull(SeguridadUsuarioId) == false)
viewSeguridadUsuario.SeguridadUsuarioId = dataReader.GetInt32(SeguridadUsuarioId);
if (dataReader.IsDBNull(SeguridadRolId) == false)
viewSeguridadUsuario.SeguridadRolId = dataReader.GetInt32(SeguridadRolId);
if (dataReader.IsDBNull(Rol) == false)
viewSeguridadUsuario.Rol = dataReader.GetString(Rol);
if (dataReader.IsDBNull(NombreUsuario) == false)
viewSeguridadUsuario.NombreUsuario = dataReader.GetString(NombreUsuario);
if (dataReader.IsDBNull(Nombres) == false)
viewSeguridadUsuario.Nombres = dataReader.GetString(Nombres);
if (dataReader.IsDBNull(Apellidos) == false)
viewSeguridadUsuario.Apellidos = dataReader.GetString(Apellidos);
if (dataReader.IsDBNull(PaswordHash) == false)
viewSeguridadUsuario.PaswordHash = dataReader.GetString(PaswordHash);
if (dataReader.IsDBNull(Salt) == false)
viewSeguridadUsuario.salt = dataReader.GetString(Salt);
if (dataReader.IsDBNull(Activo) == false)
viewSeguridadUsuario.Activo = dataReader.GetBoolean(Activo);
if (dataReader.IsDBNull(NombreCompleto) == false)
viewSeguridadUsuario.NombreCompleto = dataReader.GetString(NombreCompleto);
return viewSeguridadUsuario;
}
示例11: GetTemplate
public Template GetTemplate(SqlDataReader reader)
{
var htmlTemplate = reader["Template"].ToString();
var name = reader["Name"].ToString();
return new Template(name, htmlTemplate);
}
示例12: CustomTheme
} // End of the constructor
/// <summary>
/// Create a new custom theme from a reader
/// </summary>
/// <param name="reader"></param>
public CustomTheme(SqlDataReader reader)
{
// Set values for instance variables
this.id = Convert.ToInt32(reader["id"]);
this.name = reader["name"].ToString();
} // End of the constructor
示例13: readTable
public static List<Club> readTable(string SqlQuery, string serverName, string databaseName)
{
myConnection = new SqlConnection(serverName + ";" + databaseName + ";" + "Integrated Security=true");
try
{
myConnection.Open();
myCommand = new SqlCommand(SqlQuery, myConnection);
myReader = myCommand.ExecuteReader();
ClubList.Clear();
while(myReader.Read()) {
//Console.WriteLine(myReader[0].ToString());
//code here to map query output to club objects and put into list
ClubList.Add(new Club
{
id = myReader[0].ToString(),
//name = myReader[1].ToString(),
//address = myReader[2].ToString(),
//city = myReader[3].ToString(),
//state = myReader[4].ToString()
});
}
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
finally
{
myConnection.Close();
}
return ClubList;
}
示例14: loadlist
// Apresentar os registros da pesquisa desejada.
public void loadlist()
{
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
listBox4.Items.Clear();
listBox5.Items.Clear();
listBox6.Items.Clear();
listBox7.Items.Clear();
conexao.Open();
comando.CommandText = "SELECT * FROM Contatos";
LerDados = comando.ExecuteReader();
if (LerDados.HasRows)
{
while (LerDados.Read())
{
listBox1.Items.Add(LerDados[0].ToString());
listBox2.Items.Add(LerDados[1].ToString());
listBox3.Items.Add(LerDados[2].ToString());
listBox4.Items.Add(LerDados[3].ToString());
listBox5.Items.Add(LerDados[4].ToString());
listBox6.Items.Add(LerDados[5].ToString());
listBox7.Items.Add(LerDados[6].ToString());
}
}
conexao.Close();
}
示例15: cbo
private void cbo()
{
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("SELECT SupplierId,SupplierName FROM SUPPLIER;");
sb.Append("SELECT UserId,UserName FROM UserLogin;");
string sqlIni = sb.ToString();
com = new SqlCommand();
com.CommandText = sqlIni;
com.CommandType = CommandType.Text;
com.Connection = Conn;
dr = com.ExecuteReader();
if (dr.HasRows)
{
//supplier
DataTable dtSupplier = new DataTable();
dtSupplier.Load(dr);
cboSupplier.BeginUpdate();
cboSupplier.DisplayMember = "SupplierName";
cboSupplier.ValueMember = "SupplierId";
cboSupplier.DataSource = dtSupplier;
cboSupplier.EndUpdate();
//User
DataTable dtUserId = new DataTable();
dtUserId.Load(dr);
cboUserId.BeginUpdate();
cboUserId.DisplayMember = "UserName";
cboUserId.ValueMember = "UserId";
cboUserId.DataSource = dtUserId;
cboUserId.EndUpdate();
}
}