This question is locked. New answers and comments are not allowed.
I am building an application where users r coming from database in combobox on combobox1_Enter event.
I am also populating from another table rights for the particular user as per
selectedvaluechanged event of the same comboobx in datagridview.The problem comes when I reselect
same user error is"object not set to an instance of an object" this does not happen if I click buton for
populating usersrights in gridview when i select value in combobox.Can anybody help me with this?
here is the code:
private void UsersCombox_Enter(object sender, EventArgs e)
{
ds = null;
UsersCombox.SelectedIndex = -1;
SqlConnection mycon = new SqlConnection("Data source=DOTNET1;integrated security=true;initial catalog=examcollectiondata");
SqlDataAdapter adap = new SqlDataAdapter("select * from createuserTbl", mycon);
ds = new DataSet();
adap.Fill(ds, "createusertbl");
UsersCombox.DataSource = ds;
UsersCombox.ValueMember = "CreateUserTbl.UserName";
ds.AcceptChanges();
ds.GetChanges();
UsersCombox.Refresh();
}
private void UsersCombox_SelectedValueChanged(object sender, EventArgs e)
{
//error when reselecting value in combobox
SqlConnection mycon = new SqlConnection("data source=dotnet1;initial catalog=ExamCollectionData;integrated security=true");
//error comes in the line below
SqlDataAdapter adap = new SqlDataAdapter("select DiffForms,selectdata,insertdata,updatedata,deletedata,viewreports from useraccesstbl where users='" + UsersCombox.SelectedValue.ToString() + "'", mycon);
DataSet ds = new DataSet();
adap.Fill(ds, "useraccesstbl");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "useraccesstbl";
I am also populating from another table rights for the particular user as per
selectedvaluechanged event of the same comboobx in datagridview.The problem comes when I reselect
same user error is"object not set to an instance of an object" this does not happen if I click buton for
populating usersrights in gridview when i select value in combobox.Can anybody help me with this?
here is the code:
private void UsersCombox_Enter(object sender, EventArgs e)
{
ds = null;
UsersCombox.SelectedIndex = -1;
SqlConnection mycon = new SqlConnection("Data source=DOTNET1;integrated security=true;initial catalog=examcollectiondata");
SqlDataAdapter adap = new SqlDataAdapter("select * from createuserTbl", mycon);
ds = new DataSet();
adap.Fill(ds, "createusertbl");
UsersCombox.DataSource = ds;
UsersCombox.ValueMember = "CreateUserTbl.UserName";
ds.AcceptChanges();
ds.GetChanges();
UsersCombox.Refresh();
}
private void UsersCombox_SelectedValueChanged(object sender, EventArgs e)
{
//error when reselecting value in combobox
SqlConnection mycon = new SqlConnection("data source=dotnet1;initial catalog=ExamCollectionData;integrated security=true");
//error comes in the line below
SqlDataAdapter adap = new SqlDataAdapter("select DiffForms,selectdata,insertdata,updatedata,deletedata,viewreports from useraccesstbl where users='" + UsersCombox.SelectedValue.ToString() + "'", mycon);
DataSet ds = new DataSet();
adap.Fill(ds, "useraccesstbl");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "useraccesstbl";