C# 获取数据库满足条件的一整行数据
可以使用 SQL 查询语句来获取满足条件的一整行数据信息,例如:
string connectionString = 'Data Source=example.db';
using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
string query = 'SELECT * FROM TableName WHERE Condition = @Value';
using (var command = new SQLiteCommand(query, connection))
{
command.Parameters.AddWithValue('@Value', 'some value');
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
// 获取一整行数据信息
int id = reader.GetInt32(0);
string name = reader.GetString(1);
int age = reader.GetInt32(2);
// ...
}
}
}
}
在上述示例中,使用 SQLite 数据库,并通过 SQL 查询语句获取满足条件的一整行数据信息。在查询语句中使用了参数化查询,以避免 SQL 注入攻击。在读取数据时,使用 reader 对象的方法获取每个列的值,并将其转换为相应的数据类型。
原文地址: https://www.cveoy.top/t/topic/nemA 著作权归作者所有。请勿转载和采集!