Reputation: 63
I'm doing a query
from my Access
data base that give at result a count
, if I'm not wrong a count array give an array
, so first I need to convert the array
to int
and the show into the label
This is my query
it is on a folder named connections
and inside is the class
whit name genera-conections
where I make all the querys
that I need
/***********GET ALL THE FAKE TOOLS FROM FCH*************/
public class area_success_FCH
{
public DataTable Sfchconnect()
{
string myConnectionString = @"C:\\Users\\gutiece\\Desktop\\database\\" + "Database1.accdb";
DataTable SfchTable = new DataTable();
OleDbConnection connection = new OleDbConnection();
OleDbCommand command = new OleDbCommand();
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataSet dataset = new DataSet();
try
{
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
bool ok = System.IO.File.Exists(myConnectionString);
String qry = "SELECT COUNT(*) FROM area WHERE standby = 1 AND area = 'FCH'";
command.Connection = connection;
command.CommandText = qry;
adapter.SelectCommand = command;
command.Connection.Open();
OleDbDataReader reader = command.ExecuteReader(); // close conn after
SfchTable.Load(reader);
if (!reader.IsClosed)
{
reader.Close();
}
return SfchTable;
}
catch (Exception)
{
}
return SfchTable;
}
}
/*******************************************************/
and in the Code behind of my dashboard.aspx
a "common" page I call like this:
/********************************FILL COUNT CLOUD******************************/
connections.area_success_FCH Sfchconnect = new connections.area_success_FCH();
connections.area_success_FCH SfchTable = new connections.area_success_FCH();
/******************************************************************************/
I want to fill a Label
on dashboard.aspx
with the count
result but I don't know how to make it
hope someone can help me
Upvotes: 1
Views: 420
Reputation: 223
Use SqlCommand.ExecuteScalar()
and cast it to an int:
cmd.CommandText = "SELECT COUNT(*) FROM area WHERE standby = 1 AND area = 'FCH'";
Int32 count = (Int32) cmd.ExecuteScalar();
Then set the label:
label.Text = count.ToString();
Setting label from another class:
class withCode{
cmd.CommandText = "SELECT COUNT(*) FROM area WHERE standby = 1 AND area = 'FCH'";
public static Int32 count = (Int32)cmd.ExecuteScalar();
}
class withLabel{
label.Text = withCode.count.ToString();
}
Upvotes: 1