Hi Erol,
this is my example:
Uses "Console"
Uses "ADODB"
Dim pConnection As New ADODB_CONNECTION
Dim sConn As String
Dim sSql As String
'--------------------------------------------------------------
Function select_record(ByVal pconn As ADODB_CONNECTION, ByVal sSSS As String)
Dim pRS As New ADODB_RECORDSET
pRs.CursorLocation = %ADUSECLIENT
sSql = "select * from T_SSS where sss = " & "'" & sSSS & "';"
pRs.OPEN sSql, pConn, %ADOPENDYNAMIC, %ADLOCKOPTIMISTIC, %ADCMDTEXT
If pRS.State = %ADSTATEOPEN Then
PrintL "Sätze gefunden: " & pRs.RecordCount
End If
pRs.close
End Function
'----------------------------------
Function Add_New_Record(ByVal pConn As ADODB_CONNECTION, ByVal sISBN As String, ByVal lYear As Long, ByVal sTitle As String)
'----------------------------------
Dim pRS As New ADODB_RECORDSET
pRs.CursorLocation = %ADUSECLIENT
sSql = "select * from Titles where ISBN = " & "'" & sISBN & "';"
PrintL ssql
'pRS.Open "Titles", pConn, %ADOPENKEYSET, %ADLOCKOPTIMISTIC, %ADCMDTABLE
pRs.OPEN sSql, pConn, %ADOPENDYNAMIC, %ADLOCKOPTIMISTIC, %ADCMDTEXT
If pRS.State = %ADSTATEOPEN Then
PrintL pRs.RecordCount
If pRS.RecordCount = 1 Then
pRs.UpdateS("ISBN") = sISBN '& " " & Timer'"ich 4711"
pRs.UpdateN("Year Published") = lYear'2016
pRs.UpdateS("Title") = sTitle'"Mein erster satz"
pRs.update
'---To check if there is ana arror, always use connection and ErrorsCount method
If pConn.Errors.Count Then
PrintL "--> Fehler nach update" In %CCOLOR_FYELLOW
PrintL "Error number..:", pConn.Errors(1).Number
PrintL "Description...:", pConn.Errors(1).Description
PrintL "Source........:", pConn.Errors(1).Source
PrintL "SQLState......:", pConn.Errors(1).SQLState
PrintL "NativeError...:", pConn.Errors(1).NativeError
pConn.Errors.Clear
End If
PrintL "update" In %CCOLOR_FLIGHTRED
End If
If pRS.RecordCount = 0 Then
pRs.addnew
pRs.UpdateS("ISBN") = sISBN '& " " & Timer'"ich 4711"
pRs.UpdateN("Year Published") = lYear'2016
pRs.UpdateS("Title") = sTitle'"Mein erster satz"
pRs.UpdateS("PubID") = 69
pRs.update
'---To check if there is ana arror, always use connection and ErrorsCount method
If pConn.Errors.Count Then
PrintL "--> Fehler nach insert" In %CCOLOR_FYELLOW
PrintL "Error number..:", pConn.Errors(1).Number
PrintL "Description...:", pConn.Errors(1).Description
PrintL "Source........:", pConn.Errors(1).Source
PrintL "SQLState......:", pConn.Errors(1).SQLState
PrintL "NativeError...:", pConn.Errors(1).NativeError
pConn.Errors.Clear
End If
PrintL "insert" In %CCOLOR_FLIGHTRED
End If
PrintL " pRecordSet.Close :", pRS.CLOSE
End If
End Function
'---------------------------------------------------------------
' Connection
'---------------------------------------------------------------
'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & APP_SourcePath & "biblio.mdb"
sConn = "Provider=sqloledb;Data Source=\\server\db;Initial Catalog=KNI2M;User Id=xxxxxx;Password=yyyyy ;"
'---Set connection string
pConnection.ConnectionString = sConn
' PrintL "-Connection------------------------------------------"
PrintL " Opening ..." , pConnection.OPEN'(sConn)
' PrintL " pConnection.Connectionstring:" , pConnection.Connectionstring
PrintL " pConnection.State :" , pConnection.State
PrintL " pConnection.Version :" , pConnection.Version
PrintL "-Press a key to continue------------------------------" In %CCOLOR_FYELLOW
'---To check if there is ana arror, always use connection and ErrorsCount method
If pConnection.Errors.Count Then
'---Show all errors in one go.
'---This function also clear internal errors collection
PrintL pConnection.Errors.Msg
End If
If pConnection.State = %ADSTATEOPEN Then
' Add_New_Record(pConnection, "999999900", 9999, "Axels Test " & Date$(2) & " " & Time$(0))
select_record(pConnection, "11000238")
select_record(pConnection, "11000237")
' PrintL "-Closing press a key-------------------------------------------" In %CCOLOR_FYELLOW
'WaitKey
PrintL " pConnection.Close :", pConnection.CLOSE
Else
PrintL "-It was not possible to open a connection-" In %CCOLOR_FLIGHTRED
End If
PrintL
PrintL "-Press a key to finish-------------------------------"
WaitKey
Thanks for your assist.
Axel
Bookmarks