problem in data binding
-
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
-
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
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
-
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
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
-
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
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