Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OleDB Zugriff auf Access 2003 Decimal Feld

3 views
Skip to first unread message

Lutz

unread,
Jun 17, 2014, 4:04:32 AM6/17/14
to
Hallo!

Ich habe bei einem Kunde folgendes Phᅵnomen und weiᅵ noch nicht, woher
das kommen kᅵnnte.

Ich frage einen Decimal-Wert einer Access 2003 View ab.
Der liefert mit aber 0. In Access umgewandelt in Double bekomme ich aber
den richtigen Wert 7.

a_Fk_Preis:
SELECT t_Fk_Preis.*, CDbl([PMwst]) AS PMwstF FROM t_Fk_Preis;
[PMwst]: Dezimal 5,2

Der Code im Programm:

-------------------------------------------------------------------------------
sSql = "SELECT TP, PSt, TID, Preis, PKEN, PMwst, PMwstF FROM a_Fk_Preis" & _
" WHERE PSt=" & nPSt.ToString() & " AND TID=" & nTicketID.ToString() & ""
If GetKasSoDb().GetDataReader(sSql, drTemp, trans) Then
If drTemp.HasRows Then
If drTemp.Read() Then
nPKEN = funcDrGetInt32(drTemp, 4, 0)

sSql = sSql & vbCrLf & vbCrLf

If nPKEN > 0 Then
MsgBox("Ticketpreis fᅵr Verbindung/Preisstufe/Ticket wurde noch
nicht definiert!")
Else
sSql = sSql & "Preis1: " & drTemp.GetValue(3).ToString() & vbCrLf
fTicketPreis = funcDrGetDouble(drTemp, 3, 0)
sSql = sSql & "Preis2: " & fTicketPreis.ToString() & vbCrLf
sSql = sSql & "Preis3: " & funcDoubleAsSqlString(fTicketPreis, 2) &
vbCrLf

sSql = sSql & "MwSt1: " & drTemp.GetValue(5).ToString() & vbCrLf
fTicketMwst = funcDrGetDecimal2Double(drTemp, 5, 0)
sSql = sSql & "MwSt2: " & fTicketMwst.ToString() & vbCrLf
sSql = sSql & "MwSt3: " & funcDoubleAsSqlString(fTicketMwst, 2) & vbCrLf

sSql = sSql & "MwSt4: " & drTemp.GetValue(6).ToString() & vbCrLf
fTempMwst = funcDrGetDouble(drTemp, 6, 0)
sSql = sSql & "MwSt5: " & fTempMwst.ToString() & vbCrLf
sSql = sSql & "MwSt6: " & funcDoubleAsSqlString(fTempMwst, 2) & vbCrLf

MsgBox(sSql)

funcDbTicketPreis = True
End If
End If
End If
drTemp.Dispose()
End If

Public Function GetDataReader(ByVal sSQL As String, ByRef drDataReader
As OleDbDataReader,
Optional trans As OleDbTransaction = Nothing) As Boolean
If sSQL.Length = 0 Then Return False

Try
If IsConnectionOpened() Then
Dim cmdTemp As OleDbCommand = New OleDbCommand(sSQL, GetConnection())
If trans IsNot Nothing Then
cmdTemp.Transaction = trans
End If

drDataReader = cmdTemp.ExecuteReader()

Return True
End If
Catch ex As Exception
Dim sCatchErrMsg As String = "clsKasSoDb.GetDataReader" & vbCrLf &
vbCrLf & _
ex.Message
MsgBox(sCatchErrMsg, MsgBoxStyle.Exclamation)
End Try

Return False
End Function

Public Function funcDrGetDouble(ByRef dr As OleDb.OleDbDataReader, ByVal
nIndex As Integer, ByVal dbDefault As Double) As Double
funcDrGetDouble = dbDefault

If Not dr.IsDBNull(nIndex) Then
funcDrGetDouble = dr.GetDouble(nIndex)
End If
End Function

Public Function funcDrGetDecimal(ByRef dr As OleDb.OleDbDataReader,
ByVal nIndex As Integer, ByVal dcDefault As Decimal) As Decimal
funcDrGetDecimal = dcDefault

If Not dr.IsDBNull(nIndex) Then
funcDrGetDecimal = dr.GetDecimal(nIndex)
End If
End Function

Public Function funcDrGetDecimal2Double(ByRef dr As
OleDb.OleDbDataReader, ByVal nIndex As Integer, ByVal dbDefault As
Double) As Double
funcDrGetDecimal2Double = dbDefault

If Not dr.IsDBNull(nIndex) Then
funcDrGetDecimal2Double = CDbl(dr.GetDecimal(nIndex))
End If
End Function
-------------------------------------------------------------------------------


Das Ergebnis ist:
---------------------------
SELECT TP, PSt, TID, Preis, PKEN, PMwst, PMwstF FROM a_Fk_Preis WHERE
PSt=13 AND TID=6

Preis1: 2
Preis2: 2
Preis3: 2
MwSt1: 0,00
MwSt2: 0
MwSt3: 0
MwSt4: 7
MwSt5: 7
MwSt6: 7
---------------------------

Die Verbindung zur Datenbank wir ᅵber eine OleDbConnection realisiert.
Ziel ist wie gesagt eine Access 2003 Datenbank

-------------------------------------------------------------------------------
Dim CSB As New OleDbConnectionStringBuilder
With CSB
.DataSource = strDatabaseFilePath
.OleDbServices = DBPROPVAL_OS_ALL_EXCEPT_POOLING_AND_TXNENLISTMENT ''-4
.Provider = "Microsoft.Jet.OLEDB.4.0"

If bUsePasswd Then
' DBPasswort
.Add("Jet OLEDB:Database Password", "xxxxxxx")
End If

' DB im geteilten Modus ᅵffnen
.Add("Mode", "Share Deny None")

' Pagelocking ab Access-Version 2000,
' wird bei ᅵlteren mdb-Versionen ignoriert.
.Add("Jet OLEDB:Database Locking Mode", 1)

.PersistSecurityInfo = False

End With

Dim Cnn As OleDbConnection = New OleDbConnection
Cnn.ConnectionString = CSB.ConnectionString

Cnn.Open()
-------------------------------------------------------------------------------

Das gesamte Programm ist unter VS2012 entwickelt und .NET Framework 4


Bei zahlreichen anderen PCs klappt die Abfrage des Decimal-Wertes ohne
Probleme.
Was kann der Grund sein, warum auf dem Rechner der Decimal-Wert nicht
ordentlich abgefragt werden kann, wᅵhrend der Wert in Double umgewandelt
problemlos lesbar ist???


Danke fᅵr eure Hilfe!



--
news.albasani.net
0 new messages