Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2006, 06:32 AM
Authorized User
 
Join Date: Nov 2005
Location: , , Spain.
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
Default How to connect to DB

Hi,

I want to make a simple VBS file, which I then can run on the server so it can update every 5 min the DB.

As I am totally new to VBS, I was wodering how can I connect to the ODBC?

Any help is welcome,

Johny

Thx


Reply With Quote
  #2 (permalink)  
Old November 27th, 2006, 12:42 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Typically you will use ADO, which provides objects for connecting to and accessing databases - most typically relational (and pseudo relational) databases such as SqlServer, Oracle, Access, and MySql.

You will need to search the internet for examples on how to do this, as it is a bit much to describe here. Also, WROX (you have heard of them, I bet?) and other publishers have books on the subject.

You essentially need to at least instantiate a connection object, open it, and then execute sql against the database of that connection.
You can also optionally use a command object.

Anyway - there are literaly hundreds of resource on the intenet, and also many used books are available at very very very low prices at places like Half.com and Amazon

Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #3 (permalink)  
Old November 28th, 2006, 03:33 AM
Authorized User
 
Join Date: Nov 2005
Location: , , Spain.
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi Woodyz,

thx for the reply.

Connecting to the DB in ASP is no problem. Althought using VB is a mistery. I tied several exampls in the net, but none made it possible.

Maybe you can help me with my code:

Dim conn
set conn=CreateObject("ADODB.Connection")
conn.provider="FARMAEUROPA"
conn.open "FARMA"
set rs = Server.CreateObject("ADODB.Recordset")
sql="Select distinct codigoempleado FROM cintasempleados WHERE activo=1"
rs.open sql,conn
rs.close
MsgBox "Done"



Thx,

Johny


Reply With Quote
  #4 (permalink)  
Old November 28th, 2006, 07:26 AM
Authorized User
 
Join Date: Nov 2005
Location: , , Spain.
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi,

I have lready solved the problem.
the right code is, if anybody would like to know ;)

Dim conn
set conn=CreateObject("ADODB.Connection")
conn.open "DSN=FARMA"
set rs = CreateObject("ADODB.Recordset")
sql="Select * FROM cintasempleados WHERE activo=1"
rs.open sql,conn

HTH for people out there like me.

Now I can finally update the DB every 5 minutes.....

thx

Johny


Reply With Quote
  #5 (permalink)  
Old December 5th, 2006, 03:36 PM
Authorized User
 
Join Date: Dec 2006
Location: Mumbai, Maharastra, India.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you want to connect your DATABASE throw DSN. It is required that you first made DSN by ODBC in Control Panel.

Another way to connect to DATABASE in VB is to Add Reference of Microsoft ADODC in Your Project.

After it you can make a Connection like

Dim cn as new ADODB.Connection

Dim rs as new ADODB.Recordset 'then make a Record set.

cn.open "Driver={MYSQL ODBC 3.51 Driver};Server=localhost;
          Port=3306;Option=131072;Stmt=;Database=NameOfDatab ase;
          Uid=root;Pwd=;"

set rs=cn.execute("Select id,name from employee")

At the Place of Select you can write your Query and now
Recordset rs will indicate your Query's result.





Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need guideline about connect to DB Jose P ADO.NET 2 May 9th, 2007 11:57 AM
Connect to DB hernann C# 2005 2 July 31st, 2006 05:06 PM
Connect two or more DB at the same time?? rtr1900 Classic ASP Databases 0 May 31st, 2006 06:32 AM
connect to sql db jopay Visual C++ 0 January 12th, 2005 05:17 PM



All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.