我使用Npgsql在asp.net项目中使用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;
也不起作用。我该如何解决?
您是否在应用程序和pgAdmin中使用同一用户?如果不是,应用程序用户是否具有从表中选择的所有权限?
((我想在评论中对此提出意见,但没有答辩的意思)