I have a table in my database consisting of one column which is NewLanguage(varchar)
. I insert new languages to the table and I want to select the rows of the table and assign them to a string variable delimited by ‘,’. I try to select the languages as in the code:
public string SelectLanguagesFromDatabase()
{
try
{
NpgsqlCommand command = new NpgsqlCommand(
"SELECT string_agg("NewLanguage",',') FROM "Languages")",
dbConnection);
results = (string) command.ExecuteScalar();
command.Prepare();
}
catch( Exception ex){
MessageBox.Show(ex.ToString() );
}
return results;
}
When I test it, results
returns as null
. I want to take string representation of the rows’s values separated by ‘,’. How can I do that? Thanks.