// 假设SqlConnector是一个实现了数据库连接和执行操作的类

// 首先定义要执行的SQL语句,使用$符号可以方便地插入变量 string sqls = $"select {MeasurementPointsName} from {MeasurementPointDataRecordTable}{production} where {ProductionProductNum}= '{product}' and {ProductionProductNum} is not null";

// 调用SqlConnector的ExecuteReader方法执行SQL语句,返回一个SqlDataReader对象 SqlDataReader reader = SqlConnector.ExecuteReader(sqls);

// 循环读取结果集中的每一行数据 while (reader.Read()) { // 读取每一行中的MeasurementPointsName字段,并将其转换为字符串类型 string measurementPointsName = reader.GetString(0);

// 处理读取出来的数据,例如输出到控制台或保存到变量中
Console.WriteLine(measurementPointsName);

}

// 读取完成后,需要关闭SqlDataReader对象和数据库连接 reader.Close(); SqlConnector.CloseConnection();

c#访问数据库读 string sqls = $select MeasurementPointsName from MeasurementPointDataRecordTableproduction whereProductionProductNum= productand ProductionProductNum is not null ; SqlDat

原文地址: http://www.cveoy.top/t/topic/bt64 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录