Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21162

Records Count

$
0
0
Hi, iam using VBA

Dim cmdsqldata As ADODB.Command
Set cmdsqldata =New ADODB.Command
Dim cmdSQLdata1 As ADODB.Command
Set cmdSQLData1=New ADODB.Command
cn1.opem GetDBconnectionString_source
Set cmdsqldata1.Activeconnection=cn1

Iam uploading total two types of excel files using excel Vba.
The uploaded files are inserting to database.

If fileType="xyz" Then
QueryA="select count(Track_ID) as cnt ,max ( p_number)+1 as prn from METADATA_DB.TRACKER_VW where ID = 4"
cmdsqldata1.commandText=queryA
cmdsqlData1.commandType= adCmdText
cmdsqldata1.CommandTimeout=0
Debug.print queryA
Set rs1= cmdsqlData1.Execute()

If rs1("cnt")=0 Then
prn=1
else
Prn=rs1("prn")
End If
Else

If filetype="abc"....then also similar code here...
cn1.Close

This is for selecting files and executing insert statements into Database.
If fileType= "xyz" Then
queryA= "select count (version) as cnt,max(version)+1 as ver from SOURCE_DB.table_VW where submission_period=' "
Debug.print queryA
cmdsqldata.commandText=queryA
cmdsqldata.commandType=adCmdText
cmdsqldata.commandTimeout=0
set rs=cmdsqldata.execute()

Here there is for loop to insert all the fileds from the uploaded file...

For x=2 to rows. ex: Range("A" & x)
So x value goes...

queryB= insert into SOURCE_DB... blah blah blah,..,
cmdsqldata.commandtext = queryB
cmdsqldata.commandatype=adcmdatext
cmdsqldata.commandtimeout=0
Debug.Print queryB
Set rs= cmdsqldata.execute()
rows = rows+1
Next x
END IF

set rs= Nothing

-------------------------
public function GetDBConnectString_Source() As String
Const str_connect= "Data source= RST; Database=SOURCE_DB;Persist Security Info= True;Session Mode=ANSI;"
'My connection details to database here...login and password
End Function


My code is there as above now...i need now that no of records are inserted into database..i need records count...

Iam using ADO in my code not DAO....

I think,I will get my records count that are inserted into my SOURCE_DB from queryB
Or Recordset

If not plz guide me...

Thank you...

Viewing all articles
Browse latest Browse all 21162

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>