I'm trying to load a combobox bounded to another combobox. This is my code:
public void fill_bound_combo(SqlConnection conn, ComboBox combo, String sproc, String code, String description, Decimal parameter)
{
using (SqlCommand cmd2 = new SqlCommand(sproc))
{
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Prepare();
cmd2.Parameters.Add(new SqlParameter("@DepartmentID", parameter));
conn.Open();
cmd2.Connection = conn;
using (SqlDataReader rdr2 = cmd2.ExecuteReader(CommandBehavior.CloseConnection))
{
DataTable dt2 = new DataTable();
dt2.Columns.Add(code, typeof(decimal));
dt2.Columns.Add(description, typeof(string));
DataRow dr1 = dt2.NewRow();
dt2.Rows.Add(dr1);
while (rdr2.Read())
{
DataRow dr2 = dt2.NewRow();
dr2[0] = rdr2.GetDecimal(rdr2.GetOrdinal(code));
dr2[1] = rdr2.GetString(rdr2.GetOrdinal(description));
dt2.Rows.Add(dr2);
}
rdr2.Close();
combo.DataSource = dt2;
combo.DisplayMember = description;
combo.ValueMember = code;
}
}
}
CREATE PROCEDURE LOOKUP_TABLE
@DepartmentID decimal(4,0)
AS
BEGIN
SELECT * FROM Table1
WHERE DepartmentID=@DepartmentID
END
When i run the application I get the exception "Procedure or function LOOKUP_TABLE expects parameter @DepartmentID which was not supplied."