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. Visual Basic
  4. problem in data binding

problem in data binding

Scheduled Pinned Locked Moved Visual Basic
helpdatabasewpfwcf
4 Posts 2 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.
  • S Offline
    S Offline
    sumit21
    wrote on last edited by
    #1

    i had made a project which has 2 forms in it form1 and form2 in form1 i had made a "oledbconnection con" which is set public now, i want to use its getoledbschematable method in form2 i want to display names of all tables in my database in form2 datagrid. con is my connection to that database which is in form1 i had also done "imports system.data.oledb" in both forms ds is my datagrid in form2 my code snippet in form2 is dim f1 as new form1() dim dt as dataset f1.con.open() dt=f1.con.getoledbschematable(oledbschemaguid.tables,new object(){nothing,nothing,nothing,"table"}) ds.datasource=dt f1.con.close() plz help

    C 1 Reply Last reply
    0
    • S sumit21

      i had made a project which has 2 forms in it form1 and form2 in form1 i had made a "oledbconnection con" which is set public now, i want to use its getoledbschematable method in form2 i want to display names of all tables in my database in form2 datagrid. con is my connection to that database which is in form1 i had also done "imports system.data.oledb" in both forms ds is my datagrid in form2 my code snippet in form2 is dim f1 as new form1() dim dt as dataset f1.con.open() dt=f1.con.getoledbschematable(oledbschemaguid.tables,new object(){nothing,nothing,nothing,"table"}) ds.datasource=dt f1.con.close() plz help

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What is your problem ? How would you like us to help ? ESP ? Magic ? It's possible that the problem is that you've not called databind on ds, but who can say ? You've not said what the problem is, showed us the method you call, or anything else that would help us to help you. Your code is pretty terrible in any case. Why are you putting data access code in a form ? Surely the fact you need to create an instance of a form to call a database method is a clue that you have an exceedingly terrible design happening here ( no design, more like ). You should not declare all variables at the top of a function, do it as you need them. Why don't you just not create an intermediate dataset at all ? In an ideal world, all of the above code should look like this: ds.DataSource = MyWellDesignedDataAccessClassWithStaticFunctionsAndAStaticConnectionWithLazyInitialisation.GetSchemaTable(); ds.DataBind() Man, non-case sensitive languages make me feel dirty. I recommend you stop programming until you've read a book called Code Complete. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      S 1 Reply Last reply
      0
      • C Christian Graus

        What is your problem ? How would you like us to help ? ESP ? Magic ? It's possible that the problem is that you've not called databind on ds, but who can say ? You've not said what the problem is, showed us the method you call, or anything else that would help us to help you. Your code is pretty terrible in any case. Why are you putting data access code in a form ? Surely the fact you need to create an instance of a form to call a database method is a clue that you have an exceedingly terrible design happening here ( no design, more like ). You should not declare all variables at the top of a function, do it as you need them. Why don't you just not create an intermediate dataset at all ? In an ideal world, all of the above code should look like this: ds.DataSource = MyWellDesignedDataAccessClassWithStaticFunctionsAndAStaticConnectionWithLazyInitialisation.GetSchemaTable(); ds.DataBind() Man, non-case sensitive languages make me feel dirty. I recommend you stop programming until you've read a book called Code Complete. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

        S Offline
        S Offline
        sumit21
        wrote on last edited by
        #3

        i want to use the connection of form1 in form 2 in form2 i want to display the schema of the table which user had eneterd in form1 for this i dont want to make a new connection i form1 i had given user facility to browse any database file based on that i will make connection(which is hidden from user. he just had to browse file) now after selecting database, all the tables in that database will be apperared when user clicksone of that table , form2 will be open in which he will be able to seehis schema for this i want to use the same connection i had made in form1. therefore i am using f1.con.open() //f1 is form1 object plz help me. i had made con (oledbconnection) public

        C 1 Reply Last reply
        0
        • S sumit21

          i want to use the connection of form1 in form 2 in form2 i want to display the schema of the table which user had eneterd in form1 for this i dont want to make a new connection i form1 i had given user facility to browse any database file based on that i will make connection(which is hidden from user. he just had to browse file) now after selecting database, all the tables in that database will be apperared when user clicksone of that table , form2 will be open in which he will be able to seehis schema for this i want to use the same connection i had made in form1. therefore i am using f1.con.open() //f1 is form1 object plz help me. i had made con (oledbconnection) public

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          sumit21 wrote: plz help me. i had made con (oledbconnection) public I tried to help you. To reiterate: your design is awful. When you create a NEW instance of Form1, it's not going to contain any data entered into the instance of Form1 that was on the screen, how can it ? you need to move data access into a seperate class, and if you need data from Form1, you need to store that somewhere, or at least pass it to Form2 on initialisation ( or give Form2 a copy of Form1, if you must, assuming it still exists ). sumit21 wrote: for this i want to use the same connection i had made in form1. This is one more good reason to create a class for database connections, and have it contain a static connection object. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

          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