0
Answer

How Can I use DBTable.ConnectionProperties("User ID") in VB.NET.

Prabhu Basoor

Prabhu Basoor

14y
3.9k
1
Hello,

I'm converting VB6 to VB.NET all your help/advice is needed. I want to use DBTable.ConnectionProperties("User ID") in VB.NET. Please see below colored text.

How can i get same outcome (Set the Password, UserId property) in VB.NET? Please see below code.

Private Sub subExportDocument()

Dim crxReport As CRAXDRT.Report
Dim crxApplication As New CRAXDRT.Application
Dim adoRSDirectory As ADODB.Recordset
Dim adoRSDocPrefix As ADODB.Recordset
Dim sSql As String
Dim sDestination As String
Dim sFileName As String
Dim sDirectoryExists As String
Dim sUserID As String
Dim sPassword As String
Dim sDLLName As String
Dim sDSName As String
Dim dBalance As Double '---- M001

Dim i As Short
Dim DBTable As CRAXDRT.DatabaseTable ' Crystal Reports 9 ActiveX Designer Run Time Library (craxdrt9.dll)

On Error GoTo subExportDocument_Err

'---- Determine where we will place the PDF file.

adoRSDirectory = New ADODB.Recordset
adoConnFls.CursorLocation = ADODB.CursorLocationEnum.adUseClient
adoRSDirectory.ActiveConnection = adoConnFls

sSql = "Select EMLOCN, EMEXTN from LVEMLD"
adoRSDirectory.Open(Source:=sSql, CursorType:=ADODB.CursorTypeEnum.adOpenStatic, LockType:=ADODB.LockTypeEnum.adLockReadOnly)


'---- Determine if record found

If adoRSDirectory.RecordCount > 0 Then

adoRSDirectory.MoveFirst()
sDestination = Trim(adoRSDirectory.Fields("EMLOCN").Value) & Trim(objUser.UserID) & "\"


'---- Check If Directory exists

'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCCDEDAF088CC7"'
sDirectoryExists = Dir(sDestination & "*.*", FileAttribute.Directory)

If Trim(sDirectoryExists) = "" Then
MkDir((sDestination))
End If

'---- Determine Document prefix

adoRSDocPrefix = New ADODB.Recordset
adoConnFls.CursorLocation = ADODB.CursorLocationEnum.adUseClient
adoRSDocPrefix.ActiveConnection = adoConnFls

sSql = "Select EDPRFX from LVEMDD where EDDOCN = 'RECONCILIATION'"
adoRSDocPrefix.Open(Source:=sSql, CursorType:=ADODB.CursorTypeEnum.adOpenStatic, LockType:=ADODB.LockTypeEnum.adLockReadOnly)


'---- Determine if record found

If adoRSDocPrefix.RecordCount > 0 Then
sFileName = Trim(adoRSDocPrefix.Fields("EDPRFX").Value) & VB6.Format(Today, "yyyymmdd") & VB6.Format(TimeOfDay, "hhmmss")
sDestination = sDestination & sFileName & "." & Trim(adoRSDirectory.Fields("EMEXTN").Value)

'UPGRADE_NOTE: Object crxApplication may not be destroyed until it is garbage collected. Click for more: 'ms-help:969"'
crxApplication = Nothing


crxReport = crxApplication.OpenReport(My.Application.Info.DirectoryPath & "\" & "rptRemit_V9.rpt")
crxReport.ExportOptions.DestinationType = CRAXDRT.CRExportDestinationType.crEDTDiskFile

crxReport.ExportOptions.FormatType = CRAXDRT.CRExportFormatType.crEFTPortableDocFormat
crxReport.ExportOptions.PDFExportAllPages = True

crxReport.ExportOptions.DiskFileName = sDestination

crxReport.ExportOptions.UseReportDateFormat = True
crxReport.ExportOptions.UseReportNumberFormat = True
crxReport.DisplayProgressDialog = True

'---- Prepare files for reports

subPrepareReportFiles()


'---- Prepare Fin Rec Details

dBalance = 0
If Not fncCreateFinRecFiles(Me.Name, madoRSOpenRecHdr, madoRSOpenRecDtl, msCurrDate, "X", dRecBalance:=dBalance) Then Exit Sub


'---- Set Formula Details

crxReport.RecordSelectionFormula = ""
crxReport.RecordSelectionFormula = "{APRCFH.FHRECN} = " & fncFormatSQLText(txtRecRef.Text) & " and " & "{APRCFH.FHSUPP} = " & Val(txtSupplierNo.Text) & " and " & "{APRCFH.FHSTAT} = 'X'"

'Set connection properties for each of the table 
'DSN and Database property not changed so don't need to set them
For i = 1 To crxReport.Database.Tables.Count
'Get the table
DBTable = crxReport.Database.Tables(i)

'Set the userID property
'UPGRADE_WARNING: Couldn't resolve default property of object DBTable.ConnectionProperties(). Click for more: 'ms-help:/037B2"'
DBTable.ConnectionProperties("User ID") = Trim(objUser.UserID)

'Set the Password property
'UPGRADE_WARNING: Couldn't resolve default property of object DBTable.ConnectionProperties(). Click for more: 'ms-help://MB2"'
DBTable.ConnectionProperties("Password") = Trim(objUser.UserPassword)

'Reset the table name(ie. remove Machine and Library name from SQLQueryString
DBTable.Location = DBTable.Location
Next i

crxReport.Export((False))