How to properly add records to a database through formatted databound textboxes
-
Using VB.Net - I have an Access database. I have created bindings for my textboxes including format and parse delegates. Will display the table fields just fine. Formats the data the way I want. Problem - addnew method does not work. Does not create a new record. Simply overwrites an existing one. What's the right way to add new records with formatted, databound text boxes? Is there an article or best tips you can suggest? I've already poured over this site for one. Thanks in advance. JDFA
-
Using VB.Net - I have an Access database. I have created bindings for my textboxes including format and parse delegates. Will display the table fields just fine. Formats the data the way I want. Problem - addnew method does not work. Does not create a new record. Simply overwrites an existing one. What's the right way to add new records with formatted, databound text boxes? Is there an article or best tips you can suggest? I've already poured over this site for one. Thanks in advance. JDFA
Access can be quirky especially with autonumbers so that may be where your issue is also are you calling = .newRow (for strong typped tables) or = .Rows.newrow (for weak types) (this gets an appropo autonumber and inits all feilds in the new row with default values) Befor calling .rows.add()? make sure your not specifing the index that the row is added at. let the framework do that. Hope that helps, Frank hey...slang is the vernacular for the vernacular...wow
-
Access can be quirky especially with autonumbers so that may be where your issue is also are you calling = .newRow (for strong typped tables) or = .Rows.newrow (for weak types) (this gets an appropo autonumber and inits all feilds in the new row with default values) Befor calling .rows.add()? make sure your not specifing the index that the row is added at. let the framework do that. Hope that helps, Frank hey...slang is the vernacular for the vernacular...wow
Thanks for getting back to me and giving me some things to think about. I was using me.bindingcontext().addnew and got nowhere with it. I also tried .tables<"tablename">.addnew with no effect. It is an autonumbered table and I wasn't specifying the index. I take it that I want to create a new row, assign the values and then add it to the table. Question - what is the parse function doing for me then? So far, it only seems to be affecting existing records that I want to edit. Part of my problem may be that I don't understand yet exactly how it is to be implemented. Thanks a lot. Great site - Incredible info,generous experts.
-
Thanks for getting back to me and giving me some things to think about. I was using me.bindingcontext().addnew and got nowhere with it. I also tried .tables<"tablename">.addnew with no effect. It is an autonumbered table and I wasn't specifying the index. I take it that I want to create a new row, assign the values and then add it to the table. Question - what is the parse function doing for me then? So far, it only seems to be affecting existing records that I want to edit. Part of my problem may be that I don't understand yet exactly how it is to be implemented. Thanks a lot. Great site - Incredible info,generous experts.
Look into Parse and Format. You use those to modify the on the data in and the out for presentation and storage. IE: you have a DB that some yahoo created a collumn with "y","Y","n", and "n" in it. you want to bind it to a checkbox. if the feild was a bit/Boolean, you could directly bind it with the datasource property or by using me.checkbox.databindings.add(new binding(me.dataset1., "", "Checked ")) ...or somthing a lot like that. as an aside You can do really neat things with lookup tables and comboboxes with this command by binding the display(human readable text feild) and value(the pk feild) members oif the combobox to teh lookup table, and then binding the selectedvalue property to teh real datatables fk feild into the lookup table. I can't quote you the code to parse (to morph data from the UI to fit the database) and format(for the data coming out of the dataset into the UI), 'casuse I design my databases with some forthought, but basically you create events for the feild parse and format, and within those, you mutate back and forth. Below are some assorted ramblings with a tip or two buried within them, mainly on binding context and currencymanagers. it isn't directly in your question but if you like check it out. within your binding context are all your datasiource objects (datasets, dataviews, and datatables) each instance of which has a currency manager that points to and iterates through the datarows within. Currency managers are Great but theres a gotcha. you only get one per instance of a datasourceobject. thats Why I create dataviews to show the datatables in my datasets when I'm binding them. also no more than one control can be bound to a feild on a particular datasourceobject. but you can have multible views sitting atop the same datatable and bind two controls to the same feild but on the other view. AS a result I always get my currency managers by using dim thing as CurrencyManager = ctype(me.bindingcontext(""),currencymanger) whenever I need one (and you can just use the whole expression instead of ) Now there are some advanced members to this lib that intellisense won't point out to you by default. I recomend that you disable "Hide Advanced Members" in teht Visual Studio options. My favorite is ctype(me.bindingcontext(""),currencymanger).current.row("") to access the value in a row. not nesecarily the best form but it gets the job done. have fun, Frank