I have this code in the main wpf window:
private void ButtonChangePermissions_Click(object sender, RoutedEventArgs e)
{
if (ComboBoxSelectedProfile.SelectedIndex != -1)
{
ChangePermissionsWindow cpWindow = new ChangePermissionsWindow { parent = this };
cpWindow.Show();
}
else
{
MessageBox.Show("Please choose a profile first.");
}
}
This is the child wpf window code:
public partial class ChangePermissionsWindow : Window
{
private readonly string dbConnectionString = Properties.Settings.Default.dbConnectionString;
public postLoginWindow parent { get; set; }
public ChangePermissionsWindow()
{
InitializeComponent();
ComboBoxValuesToShow();
}
private void ComboBoxValuesToShow()
{
using (SqlConnection connection = new SqlConnection(dbConnectionString))
{
try
{
connection.Open();
if (TableFunctions.doesTableExist("ProfilePermissions", dbConnectionString))
{
string selectQuery = "SELECT Permissions from ProfilePermissions where ProfileName = @ProfileName";
using (SqlCommand command = new SqlCommand(selectQuery, connection))
{
command.Parameters.AddWithValue("@ProfileName", parent.ComboBoxSelectedProfile.Text);//This line produces the Null reference error
...Does not matter from here
}
For some reason the line:
command.Parameters.AddWithValue("@ProfileName", parent.ComboBoxSelectedProfile.Text)
causes a NullReferenceException
.
This is the exception documentation:
System.NullReferenceException: Object reference not set to an instance of an object.
at WpfApplication1.Windows.ChangePermissionsWindow.ComboBoxValuesToShow() in c:\Users\Censored\Documents\Visual Studio 2013\Projects\WpfApplication1\WpfApplication1\Windows\WindowChangePermissions.xaml.cs:line 38}
System.Exception {System.NullReferenceException
I will appreciate your help very much!