你可以幫助我嗎? 我真的不知道該怎麼做。試圖比較一個給定的ID與存儲在數據庫
我想要做的是,當我給它一個ID,比較它與存儲在數據庫中的另一個ID。
public Rubro GetRubroById(int GivenId)
{
Rubro rubro = new Rubro();
SqlCommand command = new SqlCommand
("SELECT * FROM Rubro WHERE GivenId = Id", con);
try
{
con.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
rubro.Id = reader.GetInt32(0);
rubro.Name = reader.GetString(1);
}
con.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
return rubro;
}
你沒有添加你的'SqlParameter' – Jonesopolis