1
같은 문제에 대해 다른 질문이 있다는 것을 처음 알게하겠습니다. 대부분 읽었고 다른 것들을 시도했습니다. "중복"때문에 닫을 수 없기 때문에 은입니다.C# NpgsqlCommand - AddWithValue가 대체하지 않음
저는 또한 데이터베이스로 Postgres를 사용하고 있습니다.
고급 지원에 감사드립니다.
public static string RetrieveEntry(string table, string lookup)
{
Console.WriteLine("RetrieveEntry");
if (!IsConnected())
{
return "Request Failed";
}
string str = "No poll were found that contained that info.";
string sqlstring = "SELECT * FROM "+table+" WHERE topic = '@t' OR description LIKE '@d' OR started_by = '@sb'";
NpgsqlCommand sql = new NpgsqlCommand(sqlstring,conn);
sql.Parameters.AddWithValue("@t", lookup);
sql.Parameters.AddWithValue("@d", "%" + lookup + "%");
sql.Parameters.AddWithValue("@sb", lookup);
NpgsqlDataAdapter adap = new NpgsqlDataAdapter(sqlstring,conn);
DataSet ds = new DataSet();
adap.Fill(ds);
Console.WriteLine("Table: "+ds.Tables[0].TableName+"; Tables: "+ds.Tables.Count+"; Rows: "+ds.Tables[0].Rows.Count);
if (ds.Tables[0].Rows.Count > 0) str = ""; //Remove default string
foreach (DataRow dr in ds.Tables[0].Rows)
{
str += "Topic:\t" + dr["topic"] +
"\nDesc:\t" + dr["description"].ToString().Substring(0, Math.Min(25, dr["description"].ToString().Length)) + "\n\n";
}
return str;
}