I've searched this site, and other sites to understand and get rid of this exception. Many answers, but I can't find where "I'm wrong". This i the exception:
The parameterized query '(@listenr int,@stregko nvarchar(4000))SELECT * FROM Indkøbsliste' expects the parameter '@stregko', which was not supplied.
And here i my code.
public Indkøbsliste findIndkøbslisteStregkode(string stregko, int listenr)
{
Indkøbsliste inl = new Indkøbsliste();
SqlConnection myCon = DBcon.getInstance().conn();
myCon.Open();
string query = "SELECT * FROM Indkøbsliste WHERE Stregkode = @stregko AND ListeNr = @listenr";
SqlCommand com = new SqlCommand(query, myCon);
com.Parameters.Add("@stregko", System.Data.SqlDbType.VarChar).Value = stregko;
com.Parameters.Add("@listenr", System.Data.SqlDbType.Int).Value = listenr;
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
inl.ListeNr = dr.GetInt32(1);
inl.Stregkode = dr.GetString(2);
inl.Navn = dr.GetString(3);
inl.Antal = dr.GetInt32(4);
inl.Pris = dr.GetDecimal(5);
}
myCon.Close();
return inl;
}