none
Call a class in windows form RRS feed

  • Question

  • I have this class  DropdownData which has a method call GetProcedure. The purpose of the method in the class is to call a stored procedure in the database and display the content in a Combo Box. I have four stored procedures: City, Gender, State and Civil Status. I have a form in which I have to call all the stored procedures in the form load event. What is the proper way of calling the GetProcedure in my DropdownData class? I'm a beginner in C# so I'd appreciate your comprehension and beginner-like answers. Thank you! 
    Wednesday, April 4, 2018 7:19 AM

Answers

  • DropDowndata dd = new DropDownData();

    combobox.DataSource = dd.GetProcedure(); 

    The above is assuming that the above procedure is returning a datatable that can be bound to the control.

    .NET or Java follow the same basic Object Oriented principles.

    http://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    I suggest that you get a good book that covers the basics of OO in using C#, that covers the four topics in the link below..

    https://www.codeproject.com/Articles/1059863/The-Four-Pillars-of-Object-Oriented-Design

    • Marked as answer by CodeFlop Wednesday, April 4, 2018 9:50 AM
    Wednesday, April 4, 2018 9:01 AM

All replies

  • DropDowndata dd = new DropDownData();

    combobox.DataSource = dd.GetProcedure(); 

    The above is assuming that the above procedure is returning a datatable that can be bound to the control.

    .NET or Java follow the same basic Object Oriented principles.

    http://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    I suggest that you get a good book that covers the basics of OO in using C#, that covers the four topics in the link below..

    https://www.codeproject.com/Articles/1059863/The-Four-Pillars-of-Object-Oriented-Design

    • Marked as answer by CodeFlop Wednesday, April 4, 2018 9:50 AM
    Wednesday, April 4, 2018 9:01 AM
  • Is this correct?

    On my form load

    DropDowndata dd = new DropDownData();

    dd.GetProcedure("City",comboCity); 

    dd.GetProcedure("Gender",comboGender); 

    dd.GetProcedure("State",comboState); 

    dd.GetProcedure("CivilStatus", comboCivilStatus); 

    Considering that the parameters of my GetProcedure method are GetProcedure(Storedprocedure, ComboBox)

    Thank you!

    Wednesday, April 4, 2018 9:19 AM
  • No and as long as we don't know what the SP looks like it is impossible to help you. 

    We also don't know what kind of database you use, we know that it is on a computer because you use SP but that is all. 

    In general what you have to do is bind the in .Net format put resultset using the datasource and to set the Displaymember and if you want the Valuemember 


    Success
    Cor

    Wednesday, April 4, 2018 9:31 AM
  • You need to post the code for the DropDownData class so that we can see what you are doing.
    Wednesday, April 4, 2018 10:57 AM