我正在从我的query
数据库中执行Access
,结果为count
,如果我没错,则计数数组给出array
,所以首先我需要将array
转换为int
并将节目转换为label
这是我的query
它位于名为connections
的文件夹中,里面是class
个名称genera-conections
,我在其中创建了所有querys
需要
/***********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;
}
}
/*******************************************************/
在我的dashboard.aspx
“常见”页面后面的代码中我称之为:
/********************************FILL COUNT CLOUD******************************/
connections.area_success_FCH Sfchconnect = new connections.area_success_FCH();
connections.area_success_FCH SfchTable = new connections.area_success_FCH();
/******************************************************************************/
我想在Label
上使用dashboard.aspx
结果填充count
,但我不知道如何制作
答案 0 :(得分:1)
使用SqlCommand.ExecuteScalar()
并将其转换为int:
cmd.CommandText = "SELECT COUNT(*) FROM area WHERE standby = 1 AND area = 'FCH'";
Int32 count = (Int32) cmd.ExecuteScalar();
然后设置标签:
label.Text = count.ToString();
从另一个班级设置标签:
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();
}