ok i am working on a database program i was wondering can you add a new record to a database using textboxes if so how?
Printable View
ok i am working on a database program i was wondering can you add a new record to a database using textboxes if so how?
Harrild,
This is using ADO.
Say you have two textboxes, txtBandName and txtSong. You also have to columns in the DB one named BandName the other Song. To insert a record you would use the following SQL string:
SQL = "INSERT INTO BANDS (BandName, Song) VALUES ('" & txtBandName & "', '" & txtSong & "')"
This would be passed to the Recordset object's open method like this:
rstBands.open SQL,DataConn
I haven't tried it using the Grid and ADO data control's RecordSource property so I'm not totally sure if you can. Maybe someone else can shed a little light on it.
ok looks simple enough...i think. so thats it all i need to do is edit that for an update button (i got 7 fields to add in to one database at once)?
It's more involved than that. But that is where all the action of inserting a record happens. If you'd like I can email you some of my code from class that could get you started, well if I can find it that is. We finished up with that about a week ago and I'm still looking for the class disks.
Psyrus thanks i would gladly appreciate it if you could email me the code
send it to [email protected] please.
Check your email Harrild, you should have it.
yep i got it i just need SP3 now....
Sorry, I was hoping you had it. Does anyone know if you need SP3 to use components from a program(source code) written in VB6 w/SP3 in one that doesn't have it? Did you try it Harrild? Did it work or did you get an error about missing components or something?
no it didnt work w/o SP3...and i cant download it either cos i aint got no hard disk space left....
I think you can open the files in Word or Notepad, not sure which, to view the source code. I've only heard/read it before, never tried it.
I think it is easier using ADO like this
once you have your open recordet - AdoRS
adors.addnew
adors.movelast
adors!band = txtBand.text
adors!song = txtSong.text
adors.update
If you are doing a group update you might be better using the begintrans commit trans method to stop data being half written.