473,378 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

vbs to sql-server

Hi
I've made an Access front-end using SQL-server tables. No prob so far. Now
I'd like to create some vbs-scripts, in order to do some updates to the
tables. Running from the Acces-db (vba) it works fine, after adding the
reference. However, from within vbs, it doesn't work at all. The coding goes
as far as line 2 :-(
Apparently, it can't deal with the adodb. I suppose I have to add some
declaration of the used library ? How can I solve this ?
Here is the coding :

Option Explicit
Dim cn as New ADODB.Connection, rs as New ADODB.Recordset, ctr

cn.Open ("Provider=SQLOLEDB;Data
Source=fdp01;database=fdp_db;trusted_connection=ye s")
Set rs = cn.Execute("select * from installations")
rs.MoveFirst
ctr = 0
Do While Not rs.EOF
ctr = ctr + 1
rs.MoveNext
Loop
msgbox "Total in table : " & ctr
Many tanx in advance !
Yours truly
D

Nov 13 '05 #1
3 4335
"Daedalus" <FD********@hotmail.com> wrote in
news:C4***********************@phobos.telenet-ops.be:
Hi
I've made an Access front-end using SQL-server tables. No prob so far.
Now I'd like to create some vbs-scripts, in order to do some updates
to the tables. Running from the Acces-db (vba) it works fine, after
adding the reference. However, from within vbs, it doesn't work at
all. The coding goes as far as line 2 :-(
Apparently, it can't deal with the adodb. I suppose I have to add some
declaration of the used library ? How can I solve this ?
Here is the coding :

Option Explicit
Dim cn as New ADODB.Connection, rs as New ADODB.Recordset, ctr

cn.Open ("Provider=SQLOLEDB;Data
Source=fdp01;database=fdp_db;trusted_connection=ye s")
Set rs = cn.Execute("select * from installations")
rs.MoveFirst
ctr = 0
Do While Not rs.EOF
ctr = ctr + 1
rs.MoveNext
Loop
msgbox "Total in table : " & ctr
Many tanx in advance !
Yours truly
D


VBS does not Dim variables as specific types (unless it changed )

Generally we use something like:

Dim CN

Set CN = Server.CreateObject("ADODB.Connection")

or sometimes just

Set CN = CreateObject("ADODB.Connection")

Nov 13 '05 #2

"Daedalus" <FD********@hotmail.com> wrote in message
news:C4***********************@phobos.telenet-ops.be...
Hi
I've made an Access front-end using SQL-server tables. No prob so far. Now
I'd like to create some vbs-scripts, in order to do some updates to the
tables. Running from the Acces-db (vba) it works fine, after adding the
reference. However, from within vbs, it doesn't work at all. The coding goes as far as line 2 :-(
Apparently, it can't deal with the adodb. I suppose I have to add some
declaration of the used library ? How can I solve this ?
Here is the coding :

Option Explicit
Dim cn as New ADODB.Connection, rs as New ADODB.Recordset, ctr

cn.Open ("Provider=SQLOLEDB;Data
Source=fdp01;database=fdp_db;trusted_connection=ye s")
Set rs = cn.Execute("select * from installations")
rs.MoveFirst
ctr = 0
Do While Not rs.EOF
ctr = ctr + 1
rs.MoveNext
Loop
msgbox "Total in table : " & ctr
Many tanx in advance !
Yours truly
D



vbs is not strongly typed - so you cannot write:
Dim cn as New ADODB.Connection
Instead you will have to write something more like below. You would also
have to put in some error handling code, which is not easily done in vbs.
Is vbs the only choice you have?
Option Explicit

Dim strCnn
Dim strSQL
Dim cnn
Dim rst
Dim ctr

strCnn = "Provider=sqloledb;" & _
"Data Source=fdp01;" & _
"Initial Catalog=fdp_db;" & _
"Integrated Security=SSPI;"

Set cnn = CreateObject("ADODB.Connection")

cnn.ConnectionString = strCnn

cnn.Open

strSQL = "select * from installations"

Set rst = CreateObject("ADODB.Recordset")

rst.Open strSQL, cnn

ctr = 0

While Not rst.EOF
ctr = ctr + 1
rst.MoveNext
Wend

Msgbox ctr

rst.Close

Set rst = Nothing

cnn.Close

Set cnn = Nothing


Nov 13 '05 #3
Tanx guys, this exactly what I was looking 4 !
D
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: george lewycky | last post by:
I am trying to take a field description for a column of about 200+ bytes and wrap the field into 3 lines of 70 bytes apiece in PL/SQL!!!!!! I know this can be done in SQL*Plus as show below but...
2
by: Peter | last post by:
I run most of my SQL scripts via kornshell on AIX. I use the "here-document" to run some of the smaller ones. Example: #!/bin/ksh # Analyze the table. sqlplus...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
3
by: Ira Baxter | last post by:
Hi. We are working on tools to process PL/SQL code. What we need are precise details on the full PL/SQL syntax. We have the Oracle 9/10 documentation, but it seems a little fuzzy on the...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
6
by: sghi | last post by:
Hi All, I'm new to this group and quite new to access/vba. So, shortly after beginning to write a simple application for my wife, I came across a blocking problem: I need to intercept the sql...
0
by: Medhatithi | last post by:
Hi, I have been in several ways benefiited from this site. I would like to share some sql tuning techniques(simple, but effective) with you all. SQL Tuning Tips Oracle Tips Session #6 ...
4
by: arial | last post by:
Hi all, Need your help again. string sql = " select "; sql += " q.ID, q.PALMNAME, q.CB_COMPLET, q.CMPLT_TIME, q.UNIT_NAME,"; sql += " q.CB_CREW1, q.CRW1_NAME, q.CRW1_CERT, q.CB_CREW2,...
5
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.