DataBase in User Control
-
Hi, friends. I want to create e User Control that contains two components: a textbox and a combobox. Both must be connected to a database (SqlServer, for instance). I know how to connect the combobox, also inside the UC, but in an instance of the UC I don’t. What I want is to add this new component to a form application and to make the connection, but different tables at a time. Can anybody help me? Thanks.
-
Hi, friends. I want to create e User Control that contains two components: a textbox and a combobox. Both must be connected to a database (SqlServer, for instance). I know how to connect the combobox, also inside the UC, but in an instance of the UC I don’t. What I want is to add this new component to a form application and to make the connection, but different tables at a time. Can anybody help me? Thanks.
You'll need to either provide a Constructor or a Property that allows you to pass the table name into the UserControl when it is created, and provide methods to connect and disconnect the instance - almost certainly, a property is a better idea as you can't call a parameterized constructor from the VS designer (even creating a parameterized constructor will break the designer!)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
You'll need to either provide a Constructor or a Property that allows you to pass the table name into the UserControl when it is created, and provide methods to connect and disconnect the instance - almost certainly, a property is a better idea as you can't call a parameterized constructor from the VS designer (even creating a parameterized constructor will break the designer!)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
You can have parameterized constructors if you also have a default constructor for the designer. I use parameterized constructors when I add UC's on the fly, and sometimes add a private default constructor so it can only be used on the fly.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
You can have parameterized constructors if you also have a default constructor for the designer. I use parameterized constructors when I add UC's on the fly, and sometimes add a private default constructor so it can only be used on the fly.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
They must have fixed a bug - the designer used to puke it's guts up if you dropped a UC on a form and it had an overloaded constructor. Been a while since I tried as a reason! :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!