把值付给变量,报错 "object reference not set to an instance of an object"什么意思  
  SqlConnection conn = new SqlConnection("Data Source=ZHANGYANG-PC;Initial Catalog=AdventureWorks;Integrated Security=True");
           
            ms = EmDropdown.SelectedItem.Text;
            SqlCommand EmDropdownAdapter = new SqlCommand("select EmployeeID,MaritalStatus,BirthDate from HumanResources.Employee where Title = ms ",conn);
            EmDropdownAdapter.CommandType = CommandType.Text;

解决方案 »

  1.   

    SqlConnection conn = new SqlConnection("Data Source=ZHANGYANG-PC;Initial Catalog=AdventureWorks;Integrated Security=True");
    String ms = EmDropdown.SelectedItem.Text;
    SqlCommand EmDropdownAdapter = new SqlCommand("select EmployeeID,MaritalStatus,BirthDate from HumanResources.Employee where Title = '" + ms + "'",conn);
    EmDropdownAdapter.CommandType = CommandType.Text;
      

  2.   

    未将对象引用设置到对象的实例
    ms = EmDropdown.SelectedItem.Text; 这报错了吧?
    EmDropdown或者EmDropdown.SelectedItem是null了