Access 2007 - query parametrica

mercoledì 08 ottobre 2008 - 16.42

guglielmo Profilo | Junior Member

ciao

schiedo scusa ma sono un principiante per Access 2007 (e non solo...)

ho scritto le seguenti istruzioni in ADO per leggere una tabella :

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim intResult As Integer

Set cn = CurrentProject.Connection
strSQL = "SELECT COUNT(*) As RecordCount FROM Tabella1 where campo1 = " & maschera.campo1
Set rs = New ADODB.Recordset
rs.LockType = adLockReadOnly
rs.Open strSQL, cn, adOpenStatic, adLockReadOnly, adCmdText

intResult = rs("RecordCount")
rs.Close
cn.Close


come avrei dovuto scriverle per usare una query parametrica ?

grazie

ciao



lbenaglia Profilo | Guru

>come avrei dovuto scriverle per usare una query parametrica ?
Prendi spunto da questo thread:
http://www.dotnethell.it/forum/messages.aspx?ThreadID=13913

>grazie
Prego.

Ciao!
--
Lorenzo Benaglia
Microsoft MVP - SQL Server
http://blogs.dotnethell.it/lorenzo/
http://italy.mvps.org

guglielmo Profilo | Junior Member

ciao

grazie della risposta ;
avrei una domanda (scema) da fare ; quando dici :

<<OK, supponiamo di definire in Access i seguenti oggetti:

Tabella Students

Field Data Type
---------- -----------
StudentID AutoNumber
FirstName Text(10)
LastName Text(10)

Query qrySetStudent

PARAMETERS [FirstName] Text (10), [LastName] Text (10);
INSERT INTO Students ( FirstName, LastName )
VALUES ([FirstName], [LastName]);
>>

per favore come faccio a definire qrySetStudent ?

ho dato un'occhiata alla funzione "Crea" ma non capisco come fare per inserire le istruzioni :

PARAMETERS [FirstName] Text (10), [LastName] Text (10);
INSERT INTO Students ( FirstName, LastName )
VALUES ([FirstName], [LastName]);

scusa ancora la mia ignoranza

ciao e ri-grazie


lbenaglia Profilo | Guru

>per favore come faccio a definire qrySetStudent ?
Lancia Access (2003, al momento non ho il 2007 sottomano), seleziona Queries, New, Design View, premi Close nella dialog box Show Table, nella toolbar premi il bottoncino SQL (in alto a SX) e digita il comando SQL.

>ciao e ri-grazie
Prego.

Ciao!
--
Lorenzo Benaglia
Microsoft MVP - SQL Server
http://blogs.dotnethell.it/lorenzo/
http://italy.mvps.org
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5