我一直收到此错误,我已多次检查我的代码以找到解决方案,但无济于事。
private void PopulateotherNames()
{
string query = "SELECT a nickName FROM otherNames a" +
"INNER JOIN nameNicki b ON a.Id = b.otherNamesId" +
"WHERE b.realNameId=@realNameId";
using (connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(query, connection))
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
command.Parameters.AddWithValue("@realNameId", listRealName.SelectedValue);
DataTable NickNameTable = new DataTable();
adapter.Fill(NickNameTable);
listNickName.DisplayMember = "nickName";
listNickName.ValueMember = "Id";
listNickName.DataSource = NickNameTable;
}
}
答案 0 :(得分:2)
试试这个...错过你的别名,在某些地方没有空格。查看存储过程,您将不会遇到任何此类问题。
string query = "SELECT a.nickName FROM otherNames a " +
"INNER JOIN nameNicki b ON " +
"a.Id = b.otherNamesId" +
" WHERE b.realNameId=@realNameId";