简体   繁体   English

从未分配给它,并且将始终具有其默认值

[英]is never assigned to, and will always have its default value

Im trying to select a name from a dropdown list created from a database. 我正在尝试从数据库创建的下拉列表中选择一个名称。 I cant seem to get the mane to assign. 我似乎无法分配鬃毛。

When I click the select button it does not carry the persons name in the comboBox1 through to me next lot of code. 当我单击选择按钮时,comboBox1中并没有携带人员姓名,而是向我发送下一批代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Sql;

namespace GlidingLogsGUI2
{
public partial class InstructorSelectionForm : Form
{
    List<Person> instructors = new List<Person>();
    Person selectedPerson;

    public InstructorSelectionForm()
    {
        InitializeComponent();
        this.TopMost = true;

        List<Person> instructors = new List<Person>();
        OleDbCommand com = new OleDbCommand("SELECT * FROM Personnel WHERE [Current?] = TRUE AND [Position] = ?", Program.DB_CONNECTION);
        com.Parameters.Add(new OleDbParameter("", PositionIDs.INSTRUCTOR));

        OleDbDataReader dr = com.ExecuteReader();

        while (dr.Read())
        {
            try
            {
                instructors.Add(new Person(dr));
            }
            catch
            {
            }
        }

        foreach (Person a in instructors)
        comboBox1.Items.Add(a.FirstName + " " + a.Surname);
    }

    private void Selectbutton_Click_1(object sender, EventArgs e)
    {
        if (selectedPerson == null)
        {
            MessageBox.Show("A person must be selected first");
            return;
        }

        new F5363(selectedPerson);
    }

    private void CancelButton_Click_1(object sender, EventArgs e)
    {
        this.Close();

    }

    private void InstructorSelectForm_Load(object sender, EventArgs e)
    {

    }


    }
}

You're declaring selectedPerson, but never setting it anywhere. 您在声明selectedPerson,但不要在任何地方设置它。 I suspect what you want to do is to remove the current declaration of selectedPerson and change the click event to something similar to; 我怀疑您要删除当前的selectedPerson声明,并将click事件更改为类似于以下内容的方法:

private void Selectbutton_Click_1(object sender, EventArgs e)
{  
    Person selectedPerson = comboBox1.SelectedItem as Person;
    if (selectedPerson == null)
    {
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 永远不会分配给,并且将始终具有其默认值 0 - is never assigned to, and will always have its default value 0 字段从未分配给它,并且将始终具有其默认值 - Field is never assigned to, and will always have its default value 字段“ FIELD”从未分配,并且将始终具有其默认值 - field 'FIELD' is never assigned to, and will always have its default value 警告:永远不会将字段分配给,并且始终将其默认值设置为null - Warning: Field is never assigned to, and will always have its default value null 构造函数混淆 - &#39;从未分配给,并且将始终具有其默认值&#39; - Constructor Confusion - 'never assigned to, and will always have its default value' 字段modifyDate永远不会分配给,并且始终具有其默认值0 - Field modifyDate is never assigned to, and will always have its default value 0 构造函数DI - Field永远不会分配给,并且始终具有其默认值 - Constructor DI - Field is never assigned to, and will always have its default value 字段永远不会分配给,并且始终具有默认值0 - Field is never assigned to and will always have its default value 0 字段&#39;xxx&#39;永远不会分配给,并且将始终具有其默认值null - Field 'xxx' is never assigned to, and will always have its default value null 永远不会将字段xxx分配给,并始终将其默认值设置为null - Field xxx is never assigned to, and will always have its default value null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM