Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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


 
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
 
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


 
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


 
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.









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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.