NpgsqlDataReader不返回任何内容

时间:2020-03-10 09:37:33

标签: c# sql postgresql npgsql

我在asp.net项目中使用Npgsql处理postgreSQL。

我遇到了问题-NpgSqlDataReader不返回任何内容:

        NpgsqlCommand comm = new NpgsqlCommand(command, dbConnect);
        DataTable dt = new DataTable();
        NpgsqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
        dt.Load(reader);
        return dt;

命令字符串:

string command = "SELECT mark, wmi, add_cod, manufacturer, mark_owner, country_code, country, additional_info FROM wmi_table WHERE wmi = '" + wmi.ToUpper() + "'; ";

在调试中是:

SELECT mark, wmi, add_cod, manufacturer, mark_owner, country_code, country, additional_info FROM wmi_table WHERE wmi = 'XTA'; 

所以,这是正确的字符串,我在pgAdmin的查询工具中使用了它,并返回正确的行。 与数据库的连接是稳定的(在调试中停止我的应用程序时通过pgAdmin检查)。

也尝试过:

da = new NpgsqlDataAdapter();
da.SelectCommand = new NpgsqlCommand(command, dbConnect);
DataSet ds = new DataSet("dataSet");
da.Fill(ds, "dataSet");
return ds;

也不起作用。我该如何解决?

0 个答案:

没有答案