Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataBase in User Control

DataBase in User Control

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ismael_1999
    wrote on last edited by
    #1

    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.

    OriginalGriffO 1 Reply Last reply
    0
    • I Ismael_1999

      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.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "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

      L 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        OriginalGriffO 1 Reply Last reply
        0
        • L Lost User

          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

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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!

          "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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups