How to get data by SqlDataReader.GetValue by column name
Tag : chash , By : Bjørn Lyngwa
Date : March 29 2020, 07:55 AM
will help you I use SqlDataReader.GetValue method to read values from DB: Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);
|
Reference data in SQLDataReader by column and rows or any alternative
Tag : chash , By : jumpingmattflash
Date : March 29 2020, 07:55 AM
will help you I am running a stored procedure and the result is this format , Would this work? int resign = 0;
int not_resign = 0;
int resign_count = 0;
int not_resign_count = 0;
while (reader.Read())
{
if (Convert.ToInt32(reader["Resigned"]) == 1)
{
resign = Convert.ToInt32(reader["Sum"]);
resign_count = Convert.ToInt32(reader["Count"]);
}
else
{
not_resign = Convert.ToInt32(reader["Sum"]);
not_resign_count = Convert.ToInt32(reader["Count"]);
}
}
|
How to read from a data with no column name using SqlDataReader
Tag : chash , By : Rit Li
Date : March 29 2020, 07:55 AM
hope this fix your issue I have Visual Studio 2013 Ultimate and creating application of WPF. , You can do this. reader.GetString(0); //0 stands for "the 0'th column"
|
How to print all data of one column of sqldatareader in many labels?
Date : March 29 2020, 07:55 AM
may help you . the data in SqlDataReader can be like a matrix, it depends on the query. The next snippet shows you how you can get each "cell" in your SqlDataReader: //This "while" iterates through all rows!
while(MysqlData.Read())
{
//This "for" iterates through each column of the current row!
for (int i = 0; i < MysqlData.FieldCount; i++)
{
lRoom.Add(MysqlData.GetValue(i).ToString());
}
}
|
Check a column if doesn't exists in SqlDataReader
Tag : chash , By : UpperLuck
Date : March 29 2020, 07:55 AM
I wish this help you I have to check a column if it doesn't exists in SqlDataReader. I tried using reader.IsDBNull and reader.GetOrdinal, but still getting error "Index Out of range". , use this method public static class DataRecordExtensions
{
public static bool HasColumn(this IDataRecord dr, string columnName)
{
for (int i=0; i < dr.FieldCount; i++)
{
if (dr.GetName(i).Equals(columnName, StringComparison.InvariantCultureIgnoreCase))
return true;
}
return false;
}
}
public static bool HasColumn(DbDataReader Reader, string ColumnName) {
foreach (DataRow row in Reader.GetSchemaTable().Rows) {
if (row["ColumnName"].ToString() == ColumnName)
return true;
} //Still here? Column not found.
return false;
}
|