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. How to properly add records to a database through formatted databound textboxes

How to properly add records to a database through formatted databound textboxes

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasehelptutorial
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.
  • J Offline
    J Offline
    JDFA
    wrote on last edited by
    #1

    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

    F 1 Reply Last reply
    0
    • J 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

      F Offline
      F Offline
      FrankyT
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • F FrankyT

        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

        J Offline
        J Offline
        JDFA
        wrote on last edited by
        #3

        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.

        F 1 Reply Last reply
        0
        • J JDFA

          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.

          F Offline
          F Offline
          FrankyT
          wrote on last edited by
          #4

          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

          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