OVH Cloud OVH Cloud

optimisation d'une command

2 réponses
Avatar
Sébastien
Bonjour,

je cherche a optimiser une command, et il me dit que la commande sql ne
fonctionne pas ...

je vous explique la situation,

j'ai un DataSet, qui contient une table,
j'ai fais un bout de code qui me permet de gerer directement une requette
update optimiser ou non,
si je prend le GetUpdateCommand, pas de probleme tous marche, mais si je
prend la mienne sa ne marche pas, ...
il me met "Aucune Valeur donnée pour un ou plusieur des parametre requis"
Est ce que qq pourrai m'expliquer pk ?

Commande Original
UPDATE [TBL_Test] SET [ID] = ? , [Nom] = ? , [Prenom] = ? , [Adresse] = ? ,
[Ville] = ? , [CP] = ? WHERE ( ([ID] = ?) AND ((? = 1 AND [Nom] IS NULL) OR
([Nom] = ?)) AND ((? = 1 AND [Prenom] IS NULL) OR ([Prenom] = ?)) AND ((? =
1 AND [Adresse] IS NULL) OR ([Adresse] = ?)) AND ((? = 1 AND [Ville] IS
NULL) OR ([Ville] = ?)) AND ((? = 1 AND [CP] IS NULL) OR ([CP] = ?)) )


Commande optimiser
UPDATE [TBL_Test] SET [Nom] = ? ,[Prenom] = ? ,[Adresse] = ? ,[Ville] = ?
,[CP] = ? WHERE ([ID] = ? )

'CODE
If pUpdateCmd = True Then

If pUpdateCmdOptimise = True Then

lAdapter.UpdateCommand = New
OleDb.OleDbCommand(GENCODE_CommandSQL_UpdateCommande(Me.lDataSet),
clBaseDonne.BaseDonne)

Else

lAdapter.UpdateCommand = lComdBuilder.GetUpdateCommand

End If

End If

'La fonction qui me genere la command




Public Function GENCODE_CommandSQL_UpdateCommande(ByVal pDataTable As
Data.DataTable) As String

Dim lColChamps As New Collection

Dim lColPrimaryKey As New Collection

Dim lRetour As String

For Each i As System.Data.DataColumn In pDataTable.PrimaryKey

lColPrimaryKey.Add(i.ColumnName)

Next

For i As Integer = 0 To pDataTable.Columns.Count - 1

Dim lNomChamps As String

lNomChamps = pDataTable.Columns.Item(i).ColumnName

Dim lTrouver As Boolean

lTrouver = False

For Each j As String In lColPrimaryKey

If j.Trim.ToUpper = lNomChamps.Trim.ToUpper Then

lTrouver = True

Exit For

End If

Next

If lTrouver = False Then

lColChamps.Add(lNomChamps)

End If



Next





lRetour = GENCODE_CommandSQL_UpdateCommande(lColChamps, lColPrimaryKey,
pDataTable.TableName)

lColChamps = Nothing

lColPrimaryKey = Nothing

Return lRetour

End Function

Public Function GENCODE_CommandSQL_UpdateCommande(ByVal pDataSet As
Data.DataSet) As String

Return GENCODE_CommandSQL_UpdateCommande(pDataSet.Tables(0))

End Function

Public Function GENCODE_CommandSQL_UpdateCommande(ByRef pChamps As
Collection, ByRef pPrimaryKey As Collection, ByVal pTable As String) As
String

Dim lRetour As String

Dim lUpdate As String

Dim lWhere As String

Dim lPremier As Boolean

'--------------------------------------

lPremier = True

For Each i As String In pChamps

If lPremier = False Then

lUpdate += ","

End If

lUpdate += nsBDTest.nsFunction.RCrochet(i) & " = ? "

lPremier = False

Next

'--------------------------------------

If pPrimaryKey Is Nothing OrElse pPrimaryKey.Count = 0 Then

Else

'--------------------------------------

lPremier = True

For Each i As String In pPrimaryKey

If lPremier = False Then

lWhere += ","

End If

lWhere += nsBDTest.nsFunction.RCrochet(i) & " = ? "

lPremier = False

Next

'--------------------------------------

End If

If pPrimaryKey Is Nothing OrElse pPrimaryKey.Count = 0 Then

lRetour = ""

Else

lRetour = "UPDATE " & nsBDTest.nsFunction.RCrochet(pTable) & " SET " &
lUpdate & " WHERE (" & lWhere & ")"

End If

Return lRetour

End Function

End Module

2 réponses

Avatar
aitoz
juste au cas ou ?

Tu n'as pas un champ dans ta table de destination qui oblige une saisie ???
regarde la propriété is allow null ?
Avatar
Sébastien
C bon j'ai trouver,

en faite il faux d'abort fair un GetUpdateCommande, et ensutei changer la
requette, je pensais qu'il generai les parametre mais si on fais pas cela
les parametre ne sont pas gerer ...

merci

a++
seb

"Sébastien" <Aucun> a écrit dans le message de news:
ugbZH%
Bonjour,

je cherche a optimiser une command, et il me dit que la commande sql ne
fonctionne pas ...

je vous explique la situation,

j'ai un DataSet, qui contient une table,
j'ai fais un bout de code qui me permet de gerer directement une requette
update optimiser ou non,
si je prend le GetUpdateCommand, pas de probleme tous marche, mais si je
prend la mienne sa ne marche pas, ...
il me met "Aucune Valeur donnée pour un ou plusieur des parametre requis"
Est ce que qq pourrai m'expliquer pk ?

Commande Original
UPDATE [TBL_Test] SET [ID] = ? , [Nom] = ? , [Prenom] = ? , [Adresse] = ?
, [Ville] = ? , [CP] = ? WHERE ( ([ID] = ?) AND ((? = 1 AND [Nom] IS NULL)
OR ([Nom] = ?)) AND ((? = 1 AND [Prenom] IS NULL) OR ([Prenom] = ?)) AND
((? = 1 AND [Adresse] IS NULL) OR ([Adresse] = ?)) AND ((? = 1 AND [Ville]
IS NULL) OR ([Ville] = ?)) AND ((? = 1 AND [CP] IS NULL) OR ([CP] = ?)) )


Commande optimiser
UPDATE [TBL_Test] SET [Nom] = ? ,[Prenom] = ? ,[Adresse] = ? ,[Ville] = ?
,[CP] = ? WHERE ([ID] = ? )

'CODE
If pUpdateCmd = True Then

If pUpdateCmdOptimise = True Then

lAdapter.UpdateCommand = New
OleDb.OleDbCommand(GENCODE_CommandSQL_UpdateCommande(Me.lDataSet),
clBaseDonne.BaseDonne)

Else

lAdapter.UpdateCommand = lComdBuilder.GetUpdateCommand

End If

End If

'La fonction qui me genere la command




Public Function GENCODE_CommandSQL_UpdateCommande(ByVal pDataTable As
Data.DataTable) As String

Dim lColChamps As New Collection

Dim lColPrimaryKey As New Collection

Dim lRetour As String

For Each i As System.Data.DataColumn In pDataTable.PrimaryKey

lColPrimaryKey.Add(i.ColumnName)

Next

For i As Integer = 0 To pDataTable.Columns.Count - 1

Dim lNomChamps As String

lNomChamps = pDataTable.Columns.Item(i).ColumnName

Dim lTrouver As Boolean

lTrouver = False

For Each j As String In lColPrimaryKey

If j.Trim.ToUpper = lNomChamps.Trim.ToUpper Then

lTrouver = True

Exit For

End If

Next

If lTrouver = False Then

lColChamps.Add(lNomChamps)

End If



Next





lRetour = GENCODE_CommandSQL_UpdateCommande(lColChamps, lColPrimaryKey,
pDataTable.TableName)

lColChamps = Nothing

lColPrimaryKey = Nothing

Return lRetour

End Function

Public Function GENCODE_CommandSQL_UpdateCommande(ByVal pDataSet As
Data.DataSet) As String

Return GENCODE_CommandSQL_UpdateCommande(pDataSet.Tables(0))

End Function

Public Function GENCODE_CommandSQL_UpdateCommande(ByRef pChamps As
Collection, ByRef pPrimaryKey As Collection, ByVal pTable As String) As
String

Dim lRetour As String

Dim lUpdate As String

Dim lWhere As String

Dim lPremier As Boolean

'--------------------------------------

lPremier = True

For Each i As String In pChamps

If lPremier = False Then

lUpdate += ","

End If

lUpdate += nsBDTest.nsFunction.RCrochet(i) & " = ? "

lPremier = False

Next

'--------------------------------------

If pPrimaryKey Is Nothing OrElse pPrimaryKey.Count = 0 Then

Else

'--------------------------------------

lPremier = True

For Each i As String In pPrimaryKey

If lPremier = False Then

lWhere += ","

End If

lWhere += nsBDTest.nsFunction.RCrochet(i) & " = ? "

lPremier = False

Next

'--------------------------------------

End If

If pPrimaryKey Is Nothing OrElse pPrimaryKey.Count = 0 Then

lRetour = ""

Else

lRetour = "UPDATE " & nsBDTest.nsFunction.RCrochet(pTable) & " SET " &
lUpdate & " WHERE (" & lWhere & ")"

End If

Return lRetour

End Function

End Module