因此,我已经设置了数据库连接,并且它确实连接了。
现在,我想检查表中的每一行,列isactivated
是0
还是1
,因为有点,但是我不知道该怎么做。
我会执行查询吗?是否将所有行存储在列表中,然后检查?
using (var connection = new SqlConnection(cb.ConnectionString))
{
try
{
connection.Open();
if (connection.State == ConnectionState.Open)
{
Console.WriteLine("Connected!");
}
else
{
Console.WriteLine("Failed..");
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
最佳答案
SqlCommand command = new SqlCommand("SELECT column FROM table", connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
// 0 = false, 1 = true,
bool result = (bool)reader[0];
//... do whatever you wanna do with the result
}