Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 16th, 2005, 11:46 PM
dt_aiying dt_aiying is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 93 dt_aiying User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 58 m 8 sec
Reputation Power: 4
Question Database coding in VB 6

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!

Reply With Quote
  #2  
Old November 17th, 2005, 01:33 AM
hithere's Avatar
hithere hithere is offline
Learner
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: India
Posts: 450 hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 12 h 13 m 21 sec
Reputation Power: 18
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

Reply With Quote
  #3  
Old November 17th, 2005, 01:36 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
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

Reply With Quote
  #4  
Old November 17th, 2005, 03:45 AM
dt_aiying dt_aiying is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 93 dt_aiying User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 58 m 8 sec
Reputation Power: 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.

Reply With Quote
  #5  
Old November 17th, 2005, 01:12 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
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.

Reply With Quote
  #6  
Old November 18th, 2005, 02:33 AM
dt_aiying dt_aiying is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 93 dt_aiying User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 58 m 8 sec
Reputation Power: 4
Thanks, Doug.
Your post is helpful. I'll keep that in mind.

Reply With Quote
  #7  
Old November 21st, 2005, 05:30 AM
x_c4_4u x_c4_4u is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Zimbabwe
Posts: 34 x_c4_4u User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 15 sec
Reputation Power: 5
Send a message via Yahoo to x_c4_4u
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:
Originally Posted by Doug G
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Database coding in VB 6


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT