Error does not indicate an object instance












-2














I use it DevExpress



I'm trying to add a new group, and add it to ComboBoxEdit, but the error shows that it does not indicate an object instance.
I pass the parameter in different forms... How can I do?


1 form InformationOfStudents:




    public void LoadingIDGroupTeacher(string indexTeacher)
{

sqlConnection = new SqlConnection(connectionString);
string sql = "GETGroupsTeacher";
sqlConnection.Open();
sqlCommand = new SqlCommand(sql, sqlConnection)
{
CommandType = System.Data.CommandType.StoredProcedure
};
sqlParameter = new SqlParameter
{
ParameterName = "@index",
Value = int.Parse(indexTeacher)
};
sqlCommand.Parameters.Add(sqlParameter);
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
//an error appears here

ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());
}
sqlConnection.Close();
}



2 form when I want to add a new group:




    private void BtnCancel_Click(object sender, EventArgs e)
{
new InformaitionOfStudents().LoadingIDGroupTeacher(usIndex);
Dispose();

}



T-SQL procedures:




 ALTER PROCEDURE [dbo].[GETGroupsTeacher]
@index int
AS
SELECT NameGroup FROM dbo.Groups WHERE Teacher = @index









share|improve this question


















  • 2




    Please edit and give the complete actual error message
    – WelcomeOverflow
    Dec 27 '18 at 20:07








  • 3




    Calling Dispose() on what I'm assuming is a form in a WinForms button click handler is likely not going to end well. You are Disposing of something that is in the midst of having called your handler.
    – Flydog57
    Dec 27 '18 at 20:18
















-2














I use it DevExpress



I'm trying to add a new group, and add it to ComboBoxEdit, but the error shows that it does not indicate an object instance.
I pass the parameter in different forms... How can I do?


1 form InformationOfStudents:




    public void LoadingIDGroupTeacher(string indexTeacher)
{

sqlConnection = new SqlConnection(connectionString);
string sql = "GETGroupsTeacher";
sqlConnection.Open();
sqlCommand = new SqlCommand(sql, sqlConnection)
{
CommandType = System.Data.CommandType.StoredProcedure
};
sqlParameter = new SqlParameter
{
ParameterName = "@index",
Value = int.Parse(indexTeacher)
};
sqlCommand.Parameters.Add(sqlParameter);
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
//an error appears here

ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());
}
sqlConnection.Close();
}



2 form when I want to add a new group:




    private void BtnCancel_Click(object sender, EventArgs e)
{
new InformaitionOfStudents().LoadingIDGroupTeacher(usIndex);
Dispose();

}



T-SQL procedures:




 ALTER PROCEDURE [dbo].[GETGroupsTeacher]
@index int
AS
SELECT NameGroup FROM dbo.Groups WHERE Teacher = @index









share|improve this question


















  • 2




    Please edit and give the complete actual error message
    – WelcomeOverflow
    Dec 27 '18 at 20:07








  • 3




    Calling Dispose() on what I'm assuming is a form in a WinForms button click handler is likely not going to end well. You are Disposing of something that is in the midst of having called your handler.
    – Flydog57
    Dec 27 '18 at 20:18














-2












-2








-2







I use it DevExpress



I'm trying to add a new group, and add it to ComboBoxEdit, but the error shows that it does not indicate an object instance.
I pass the parameter in different forms... How can I do?


1 form InformationOfStudents:




    public void LoadingIDGroupTeacher(string indexTeacher)
{

sqlConnection = new SqlConnection(connectionString);
string sql = "GETGroupsTeacher";
sqlConnection.Open();
sqlCommand = new SqlCommand(sql, sqlConnection)
{
CommandType = System.Data.CommandType.StoredProcedure
};
sqlParameter = new SqlParameter
{
ParameterName = "@index",
Value = int.Parse(indexTeacher)
};
sqlCommand.Parameters.Add(sqlParameter);
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
//an error appears here

ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());
}
sqlConnection.Close();
}



2 form when I want to add a new group:




    private void BtnCancel_Click(object sender, EventArgs e)
{
new InformaitionOfStudents().LoadingIDGroupTeacher(usIndex);
Dispose();

}



T-SQL procedures:




 ALTER PROCEDURE [dbo].[GETGroupsTeacher]
@index int
AS
SELECT NameGroup FROM dbo.Groups WHERE Teacher = @index









share|improve this question













I use it DevExpress



I'm trying to add a new group, and add it to ComboBoxEdit, but the error shows that it does not indicate an object instance.
I pass the parameter in different forms... How can I do?


1 form InformationOfStudents:




    public void LoadingIDGroupTeacher(string indexTeacher)
{

sqlConnection = new SqlConnection(connectionString);
string sql = "GETGroupsTeacher";
sqlConnection.Open();
sqlCommand = new SqlCommand(sql, sqlConnection)
{
CommandType = System.Data.CommandType.StoredProcedure
};
sqlParameter = new SqlParameter
{
ParameterName = "@index",
Value = int.Parse(indexTeacher)
};
sqlCommand.Parameters.Add(sqlParameter);
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
//an error appears here

ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());
}
sqlConnection.Close();
}



2 form when I want to add a new group:




    private void BtnCancel_Click(object sender, EventArgs e)
{
new InformaitionOfStudents().LoadingIDGroupTeacher(usIndex);
Dispose();

}



T-SQL procedures:




 ALTER PROCEDURE [dbo].[GETGroupsTeacher]
@index int
AS
SELECT NameGroup FROM dbo.Groups WHERE Teacher = @index






c# winforms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 27 '18 at 20:05









Юрий Куликовский

212




212








  • 2




    Please edit and give the complete actual error message
    – WelcomeOverflow
    Dec 27 '18 at 20:07








  • 3




    Calling Dispose() on what I'm assuming is a form in a WinForms button click handler is likely not going to end well. You are Disposing of something that is in the midst of having called your handler.
    – Flydog57
    Dec 27 '18 at 20:18














  • 2




    Please edit and give the complete actual error message
    – WelcomeOverflow
    Dec 27 '18 at 20:07








  • 3




    Calling Dispose() on what I'm assuming is a form in a WinForms button click handler is likely not going to end well. You are Disposing of something that is in the midst of having called your handler.
    – Flydog57
    Dec 27 '18 at 20:18








2




2




Please edit and give the complete actual error message
– WelcomeOverflow
Dec 27 '18 at 20:07






Please edit and give the complete actual error message
– WelcomeOverflow
Dec 27 '18 at 20:07






3




3




Calling Dispose() on what I'm assuming is a form in a WinForms button click handler is likely not going to end well. You are Disposing of something that is in the midst of having called your handler.
– Flydog57
Dec 27 '18 at 20:18




Calling Dispose() on what I'm assuming is a form in a WinForms button click handler is likely not going to end well. You are Disposing of something that is in the midst of having called your handler.
– Flydog57
Dec 27 '18 at 20:18












2 Answers
2






active

oldest

votes


















0














Add:



     if(!sqlDataReader.IsDBNull(0))
ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());


Or:



     ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0)?.ToString() ?? ""); 





share|improve this answer































    0














    If ComboBoxGroups is a DevExpress DevExpress.Xpf.Editors.ComboBoxEdit control you should probably use:



    ComboBoxGroups.Items.Add(sqlDataReader.GetValue(0).ToString());


    and not:



    ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString()); 


    And the Dispose(); in the button event handler in "2 form" will Dispose the dialog "2 form" so that's probably not a good idea.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53950303%2ferror-does-not-indicate-an-object-instance%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Add:



           if(!sqlDataReader.IsDBNull(0))
      ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());


      Or:



           ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0)?.ToString() ?? ""); 





      share|improve this answer




























        0














        Add:



             if(!sqlDataReader.IsDBNull(0))
        ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());


        Or:



             ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0)?.ToString() ?? ""); 





        share|improve this answer


























          0












          0








          0






          Add:



               if(!sqlDataReader.IsDBNull(0))
          ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());


          Or:



               ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0)?.ToString() ?? ""); 





          share|improve this answer














          Add:



               if(!sqlDataReader.IsDBNull(0))
          ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString());


          Or:



               ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0)?.ToString() ?? ""); 






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 27 '18 at 21:49

























          answered Dec 27 '18 at 21:06









          Shimon Lebovits

          634




          634

























              0














              If ComboBoxGroups is a DevExpress DevExpress.Xpf.Editors.ComboBoxEdit control you should probably use:



              ComboBoxGroups.Items.Add(sqlDataReader.GetValue(0).ToString());


              and not:



              ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString()); 


              And the Dispose(); in the button event handler in "2 form" will Dispose the dialog "2 form" so that's probably not a good idea.






              share|improve this answer


























                0














                If ComboBoxGroups is a DevExpress DevExpress.Xpf.Editors.ComboBoxEdit control you should probably use:



                ComboBoxGroups.Items.Add(sqlDataReader.GetValue(0).ToString());


                and not:



                ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString()); 


                And the Dispose(); in the button event handler in "2 form" will Dispose the dialog "2 form" so that's probably not a good idea.






                share|improve this answer
























                  0












                  0








                  0






                  If ComboBoxGroups is a DevExpress DevExpress.Xpf.Editors.ComboBoxEdit control you should probably use:



                  ComboBoxGroups.Items.Add(sqlDataReader.GetValue(0).ToString());


                  and not:



                  ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString()); 


                  And the Dispose(); in the button event handler in "2 form" will Dispose the dialog "2 form" so that's probably not a good idea.






                  share|improve this answer












                  If ComboBoxGroups is a DevExpress DevExpress.Xpf.Editors.ComboBoxEdit control you should probably use:



                  ComboBoxGroups.Items.Add(sqlDataReader.GetValue(0).ToString());


                  and not:



                  ComboBoxGroups.Properties.Items.Add(sqlDataReader.GetValue(0).ToString()); 


                  And the Dispose(); in the button event handler in "2 form" will Dispose the dialog "2 form" so that's probably not a good idea.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 27 '18 at 22:09









                  Jens Granlund

                  4,14312427




                  4,14312427






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53950303%2ferror-does-not-indicate-an-object-instance%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas