C# postresql npgsql c参数不工作

C# postresql npgsql c参数不工作,c#,postgresql,C#,Postgresql,我已经在谷歌上搜索/阅读了几个小时,只是越来越沮丧 这是我的密码 NpgsqlConnection conn = new NpgsqlConnection("Server=" + Properties.Settings.Default.db_server + ";Port=" + Properties.Settings.Default.db_port + ";User Id=" + Properties.Settings.Default.db_user + ";Password=" + Prop

我已经在谷歌上搜索/阅读了几个小时,只是越来越沮丧

这是我的密码

NpgsqlConnection conn = new NpgsqlConnection("Server=" + Properties.Settings.Default.db_server + ";Port=" + Properties.Settings.Default.db_port + ";User Id=" + Properties.Settings.Default.db_user + ";Password=" + Properties.Settings.Default.db_password + ";Database=" + Properties.Settings.Default.db_database + ";");
conn.Open();
NpgsqlCommand command = new NpgsqlCommand("SELECT user_password FROM users WHERE user_initials = :value1", conn);
// Now add the parameter to the parameter collection of the command specifying its type.
command.Parameters.Add(new NpgsqlParameter("value1", NpgsqlTypes.NpgsqlDbType.Char));

// Now, add a value to it and later execute the command as usual.
command.Parameters[0].Value = initials.Text;
string userPass;

try
{
    userPass = (string)command.ExecuteScalar();
    MessageBox.Show(userPass);
}
finally
{
    conn.Close();
}

如果初始值文本中有有效值,则只返回一个空白结果。如果我硬编码首字母,我会得到一个文本结果。

尝试使用带有@symbol like的参数:从user\u initials=@value1的用户中选择user\u password,然后添加类似command.Parameters的参数。AddWithValue@value1,首字母缩写。文本;那起作用了。。。但是1。它为什么起作用?二,。我在哪里能找到那个?我觉得除了手册之外,在这方面完全缺乏资源,每一个该死的教程都是基本的。唉。我觉得我不应该离开mysql。我记得,新版本的NpgsqlCommand支持带@symbol的参数,但我不确定,但我认为它仍然支持带:。见: