ComboBox显示System.Data.DatarowView首先



因此,在WindowsForm中,我有2个ComboBoxes和一个CheckedListBox用于练习。当您选择字体效果(健美操,重量,有氧运动等)和肌肉小组(三头肌,胸部,背部,前臂等)时,您应该从CheckedListBox中脱离练习。

两个 ComboBoxes'默认值都是1,因此它应该在 CheckedListBox中显示俯卧撑,因为 TypeFitness = 1是钙质, MuscleGroup = 1是前肩。

相反,它显示了 System.Data.DataRowView,但是第二次我以表格显示正确的形式选择健美操。有没有办法做到这一点,因此立即显示练习?

System.Data.DataRowView仅显示上一个选择没有结果的何时)

代码:

private void Exercises()
{
    string query = "SELECT X.ExerciseId, X.Naam FROM Xercises AS X " +
            "INNER JOIN MG_Exercise AS MGX ON MGX.ExerciseId = X.ExerciseId " +
            "WHERE MGX.MuscleId = @MuscleId AND X.FitnessId = @FitnessId";
    using (connection = new SqlConnection(connectionString))
    using (SqlCommand command = new SqlCommand(query, connection))
    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
    {
        SqlParameter param = command.Parameters.AddWithValue("@MuscleId", comBoxMuscleGroup.SelectedValue);
        SqlParameter param2 = command.Parameters.AddWithValue("@FitnessId", comBoxTypeFitness.SelectedValue);
        if(param.Value == null)
        {
            param.Value = DBNull.Value;
        }
        if(param2.Value == null)
        {
            param2.Value = DBNull.Value;
        }
        DataTable Xdata = new DataTable();
        adapter.Fill(Xdata);
        clbXcercises.DisplayMember = "Naam";
        clbXcercises.ValueMember = "X.ExerciseId";
        clbXcercises.DataSource = Xdata;
    }
}

问题是我将DataSource放置上次Exercises()。所以应该是:

clbXcercises.DataSource = Xdata;
clbXcercises.DisplayMember = "Naam";
clbXcercises.ValueMember = "X.ExerciseId";

相关内容

  • 没有找到相关文章

最新更新