|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi everyone,
In my VB program, I am required to save data into the database and later view data from the database. Most of the tutorials / examples that I have gone through uses the ADO data control to perform these tasks. However, I have been requested to do these tasks by just doing VB coding. (so that in the future, whenever there are any changes, I could just maintain the program by modifying the codes, and not having to go through all the ADO data controls to modify them one at a time) I think I am suppose to do coding for opening a connection to the database, use SQL statements to manipulate the data from the database, display data into the form and finally closing the database connection. Could anyone please help me with this? I just need some rough ideas on how to go about with the VB database coding. Thankies in advance! |
|
#2
|
||||
|
||||
|
Hi
THis is a sample program Code:
dim cn as new adodb.connection dim rs as new adodb.recordset dim cmd as new adodb.command '''' fetching data cn.open connectionstring '' opening connection rs.open "select * from table_name where id = '101'", cn, adopenkeyset ''' fetching data if rs.recordcount > 0 then '' checking whether data exists text1.text = rs(0) text2.text = rs(1) and so on. this depends upon the no. of columns u have end if '' for updating record cmd.activeconnection = cn cmd.commandtext = "update table_name set column_name = '" & text1.text & "' where id = '101' cmd.execute i hope u got some idea. for any query plz feel free to ask me |
|
#3
|
|||
|
|||
|
You're going to have to use ADO or some db abstraction layer, unless you want to try to write low-level database code, which would be an impossible task.
I'm unclear what your concern about using ADO is all about. hithere's example uses ADO
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#4
|
|||
|
|||
|
Hithere and Doug, thanks for the help given.
Doug, I was referring to the ADO 'data control' in my post. When I first tried using the ADO data control for my program, I was asked to not use the ADO data control - just in case that if changes are needed to be done in the future for database settings, the programmer maintaining the program would just need to change the coding for the database settings only once (and not having going through one ADO data control after another to change the setting). So, at the coding level for the program's interaction with the database, ADO will still need to be used, just in a slightly different way. Doug, I apologize for this, perhaps I do not know much of VB programming as I am just at a beginner's level for this. Anyway, hithere, thanks for the code example, I have some rough ideas on how to proceed with this. I have also managed to get hold of more similar examples from a Microsoft book. |
|
#5
|
|||
|
|||
|
You can set the recordsource of an ado data control from your code, you don't have to enter the connection and sql at design time. You could write an initialization routine for you application that sets up all the databound controls at runtime, that way only the initialization routine needs changing if your db changes.
|
|
#6
|
|||
|
|||
|
Thanks, Doug.
Your post is helpful. I'll keep that in mind. |
|
#7
|
|||
|
|||
|
me too
thanx for this hint doug
i had moved away from adodc because of the need to dynamically update controls.now, i am back to adodc. thanx again you're a star Quote:
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Database coding in VB 6 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|