Changé urlPic VB6

Résolu
Signaler
Messages postés
16
Date d'inscription
mercredi 21 décembre 2005
Statut
Membre
Dernière intervention
17 janvier 2010
-
Messages postés
14008
Date d'inscription
samedi 29 décembre 2001
Statut
Modérateur
Dernière intervention
28 août 2015
-
Bon soire,

J'ai sauvé un Field dans ma base de données appelée URLPic, type memo. Je veux quand je changer le photo sur le URLPic filed, il reste inchangé à moins que je sélectionne une nouvelle image. Et si je sélectionne une nouvelle image URLPic field dois etre remplacer.

Merci beaucoup!!!

4 réponses

Messages postés
14008
Date d'inscription
samedi 29 décembre 2001
Statut
Modérateur
Dernière intervention
28 août 2015
81
Salut
Désolé, je ne comprends pas.
"quand je changer le photo sur le URLPic filed, il reste inchangé"
il va falloir prendre une décision : tu changes mais tu ne changes pas ...

"si je sélectionne une nouvelle image"
Sélectionne dans quoi ? où ?

Comment fais-tu les mises à jour de tes données dans ta base ? quelle méthode ?
Si c'est par SQL, il te suffit de faire une commande "Update" sur ta table.
Mais sans plus d'explication, difficile de te dire quoi faire.

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
Messages postés
16
Date d'inscription
mercredi 21 décembre 2005
Statut
Membre
Dernière intervention
17 janvier 2010

Pardonnez mon français.
J'ai msflexgrid . Au moment où je traverse Gridu et ensuite je tente de modifier les informations dans une row
me donne l'erreur suivante

Run-time error 3709
The connection cannot be used to perform this operation. It is either closed or invalid in this context

Option Explicit
Dim mobjrec As clsMyADOConn
Public pic As String
Public pic2 As String
Public pic3 As String
Dim lPic As Picture

Private Sub adaug_Click()
'Testez campurile
If codpanou.Text = "" Then
    MsgBox "Nu ati completat codul fata !", vbInformation + vbOKOnly, "Err"
    codpanou.SetFocus
    
ElseIf Combo1.Text = "" Then
    MsgBox "Nu ati ales tipul fata!", vbInformation + vbOKOnly, "Err"
    Combo1.SetFocus
    
ElseIf Combo3.Text = "" Then
    MsgBox "Iluminat DA sau NU!", vbInformation + vbOKOnly, "Err"
    Combo3.SetFocus

ElseIf Combo4 = "" Then
    MsgBox "Disponibil DA sau NU!", vbInformation + vbOKOnly, "Err"
    Combo4.SetFocus
    
Else
Call Connect
mobjrec.SQL = "select * from PANOURI  where CodPanou='" & codpanou.Text & "'"
   mobjrec.RSOpen
    If (rst.RecordCount > 0) Then
        MsgBox "Cod Panou deja existent !!!", vbInformation, "Eroare"
        codpanou.Text = ""
        codpanou.SetFocus
        Call Deconnect
    Else
    
mobjrec.SQL = "select * from PANOURI"
    mobjrec.RSOpen
    With rst
        .AddNew
        .Fields!codpanou = "" & codpanou.Text
        .Fields!Judet = 0 + Combo5.ItemData(Combo5.ListIndex)
        .Fields!Localitate = 0 + Combo7.ItemData(Combo7.ListIndex)
        .Fields!adresa = "" & adresa.Text
        .Fields!Zona = "" & Text2.Text
        .Fields![Detalii locatie] = "" & Text3.Text
        .Fields!Tip = 0 + Combo1.ItemData(Combo1.ListIndex)
        .Fields!Dimensiuni = "" & Text1.Text
        .Fields!Iluminat = 0 + Combo3.ItemData(Combo3.ListIndex)
        .Fields!Construit = 0 + Combo4.ItemData(Combo4.ListIndex)
        '.Fields![Nr Fete] = 0 + Combo2.ItemData(Combo2.ListIndex)
        .Fields!pret = 0 + Val(pret.Text)
        .Fields!Poza = pic
        .Fields!Poza2 = pic2
        .Fields!Poza3 = pic3
        .Update
    End With
    mobjrec.Class_Terminate
    Call cancel_Click
    MsgBox "Informatiile despre panou au fost salvate!"
    Call LoadFlexGrid
End If
End If
End Sub

Private Sub cancel_Click()
    IDPanou.Text = ""
    codpanou.Text = ""
    Text1.Text = ""
    Text2.Text = ""
    adresa.Text = ""
    Text3.Text = ""
   
    Call Form_Load
End Sub

Private Sub imprima_Click()
DataReport2.Show 1
End Sub

Private Sub inchide_Click()
Unload Me
End Sub

Private Sub Form_Load()
Set mobjrec = New clsMyADOConn
    Call Connect
    
    mobjrec.SQL = "SELECT * From TIPURIPANOURI ORDER BY TipPanou;"
    Call mobjrec.RSOpen
    Combo1.Clear
    While Not rst.EOF
        Combo1.AddItem rst(1)
        Combo1.ItemData(Combo1.NewIndex) = rst(0)
    rst.MoveNext
    Wend
    mobjrec.Class_Terminate
    
        
    Set mobjrec = New clsMyADOConn
    Call Connect
    mobjrec.SQL = "SELECT * From RASP ORDER BY Iluminat"
    Call mobjrec.RSOpen
    Combo3.Clear
    While Not rst.EOF
        Combo3.AddItem rst(1)
        Combo3.ItemData(Combo3.NewIndex) = rst(0)
    rst.MoveNext
    Wend
    mobjrec.Class_Terminate
    
    Set mobjrec = New clsMyADOConn
    Call Connect
    mobjrec.SQL = "SELECT * From RASP ORDER BY Iluminat"
    Call mobjrec.RSOpen
    Combo4.Clear
    While Not rst.EOF
        Combo4.AddItem rst(1)
        Combo4.ItemData(Combo4.NewIndex) = rst(0)
    rst.MoveNext
    Wend
    mobjrec.Class_Terminate
    
    Set mobjrec = New clsMyADOConn
    Call Connect
    mobjrec.SQL = "SELECT * From LOCALITATI ORDER BY NumeL"
    Call mobjrec.RSOpen
    Combo7.Clear
    While Not rst.EOF
        Combo7.AddItem rst(1)
        Combo7.ItemData(Combo7.NewIndex) = rst(0)
    rst.MoveNext
    Wend
    mobjrec.Class_Terminate
    
    Set mobjrec = New clsMyADOConn
    Call Connect
    mobjrec.SQL = "SELECT * From JUDETE ORDER BY NumeJ"
    Call mobjrec.RSOpen
    Combo5.Clear
    While Not rst.EOF
        Combo5.AddItem rst(1)
        Combo5.ItemData(Combo5.NewIndex) = rst(0)
    rst.MoveNext
    Wend
    mobjrec.Class_Terminate
    
    Call LoadFlexGrid
    
End Sub

Private Sub LoadFlexGrid()
    ListC.Rows = 1
    mobjrec.SQL "SELECT PANOURI.IdPanou, PANOURI.CodPanou AS [Cod Fata], JUDETE.NumeJ AS Judet, LOCALITATI.NumeL AS Localitate, PANOURI.Adresa, PANOURI.Zona, PANOURI.[Detalii locatie], TIPURIPANOURI.TipPanou, PANOURI.Dimensiuni, Query3.Iluminat, Query3.Construit, PANOURI.Pret, PANOURI.Poza, PANOURI.Poza2, PANOURI.Poza3 FROM TIPURIPANOURI INNER JOIN ((JUDETE INNER JOIN LOCALITATI ON JUDETE.IDJud LOCALITATI.Judet) INNER JOIN (Query3 INNER JOIN PANOURI ON Query3.IdPanou = PANOURI.IdPanou) ON LOCALITATI.IDLoc = PANOURI.Localitate) ON TIPURIPANOURI.IDTipPanou = PANOURI.Tip;"
    'SELECT PANOURI.IdPanou, PANOURI.CodPanou AS [Cod Fata], JUDETE.NumeJ AS Judet, LOCALITATI.NumeL AS Localitati, PANOURI.Adresa, PANOURI.Zona, PANOURI.[Detalii locatie], TIPURIPANOURI.TipPanou, PANOURI.Dimensiuni, Query3.Iluminat, Query3.Construit, PANOURI.Poza FROM TIPURIPANOURI INNER JOIN (Query3 INNER JOIN ((JUDETE INNER JOIN LOCALITATI ON JUDETE.IDJud=LOCALITATI.Judet) INNER JOIN PANOURI ON LOCALITATI.IDLoc=PANOURI.Localitate) ON Query3.IdPanou=PANOURI.IdPanou) ON TIPURIPANOURI.IDTipPanou=PANOURI.Tip;"
    'SELECT PANOURI.IdPanou, PANOURI.CodPanou as [Cod Fata], JUDETE.NumeJ as Judet, LOCALITATI.NumeL as Localitati, PANOURI.Adresa, PANOURI.Zona, PANOURI.[Detalii locatie], TIPURIPANOURI.TipPanou, PANOURI.Dimensiuni, Query3.Iluminat, Query3.Construit, PANOURI.Poza FROM TIPURIPANOURI INNER JOIN (Query3 INNER JOIN ((JUDETE INNER JOIN LOCALITATI ON JUDETE.IDJud = LOCALITATI.Judet) INNER JOIN PANOURI ON LOCALITATI.IDLoc = PANOURI.Localitate) ON Query3.IdPanou = PANOURI.IdPanou) ON TIPURIPANOURI.IDTipPanou = PANOURI.Tip;"
    'SELECT PANOURI.IdPanou, PANOURI.CodPanou, TIPURIPANOURI.TipPanou, PANOURI.Dimensiuni, FETE.NrFete as [Nr Fete], PANOURI.Regiune, PANOURI.Adresa, LOCALITATI.NumeL as Localitate, Query3.Iluminat, Query3.Disponibil, PANOURI.Pret, PANOURI.Poza FROM TIPURIPANOURI INNER JOIN (LOCALITATI INNER JOIN (FETE INNER JOIN (PANOURI INNER JOIN Query3 ON PANOURI.IdPanou = Query3.IdPanou) ON FETE.IDFete = PANOURI.[Nr Fete]) ON LOCALITATI.IDLoc = PANOURI.Localitate) ON TIPURIPANOURI.IDTipPanou = PANOURI.Tip;"
    Call mobjrec.RSOpen
    While Not rst.EOF()
        
         ListC.AddItem Chr(9) & rst(0) & Chr(9) & rst(1) & Chr(9) & rst(2) & Chr(9) & rst(3) & Chr(9) & rst(4) & Chr(9) & rst(5) & Chr(9) & rst(6) & Chr(9) & rst(7) & Chr(9) & rst(8) & Chr(9) & rst(9) & Chr(9) & rst(10) & Chr(9) & rst(11) & Chr(9) & rst(12) & Chr(9) & rst(13) & Chr(9) & rst(14)
         rst.MoveNext
    Wend
    ListC.AllowUserResizing = flexResizeBoth
    Call mobjrec.Class_Terminate
End Sub

Private Sub ListC_Click()

    IDPanou.Text = ListC.TextMatrix(ListC.Row, 1)
    codpanou.Text = ListC.TextMatrix(ListC.Row, 2)
    Combo5.Text = ListC.TextMatrix(ListC.Row, 3)
    Combo7.Text = ListC.TextMatrix(ListC.Row, 4)
    adresa.Text = ListC.TextMatrix(ListC.Row, 5)
    Text2.Text = ListC.TextMatrix(ListC.Row, 6)
    Text3.Text = ListC.TextMatrix(ListC.Row, 7)
    Combo1.Text = ListC.TextMatrix(ListC.Row, 8)
    Text1.Text = ListC.TextMatrix(ListC.Row, 9)
    Combo3.Text = ListC.TextMatrix(ListC.Row, 10)
    Combo4.Text = ListC.TextMatrix(ListC.Row, 11)
    pret.Text = ListC.TextMatrix(ListC.Row, 12)
    Picture1.Picture = Nothing
    Picture2.Picture = Nothing
    Picture3.Picture = Nothing
    
    Call Connect
    If ListC.Rows <> 1 Then
    mobjrec.SQL "SELECT Poza FROM PANOURI where IdPanou " & ListC.TextMatrix(ListC.Row, 1)
    Call mobjrec.RSOpen
    If rst(0) <> "" Then
      Me.Picture1.AutoRedraw = True
        Picture1.Picture = LoadPicture(rst(0))
        ResizePicture Me.Picture1, Picture1.Picture
    End If
    End If
    Call Deconnect
    
    Call Connect
    If ListC.Rows <> 1 Then
    mobjrec.SQL "SELECT Poza2 FROM PANOURI where IdPanou " & ListC.TextMatrix(ListC.Row, 1)
    Call mobjrec.RSOpen
    If rst(0) <> "" Then
      Me.Picture2.AutoRedraw = True
        Picture2.Picture = LoadPicture(rst(0))
        ResizePicture Me.Picture2, Picture2.Picture
    End If
    End If
    Call Deconnect
     
    Call Connect
    If ListC.Rows <> 1 Then
    mobjrec.SQL "SELECT Poza3 FROM PANOURI where IdPanou " & ListC.TextMatrix(ListC.Row, 1)
    Call mobjrec.RSOpen
    If rst(0) <> "" Then
      Me.Picture3.AutoRedraw = True
        Picture3.Picture = LoadPicture(rst(0))
        ResizePicture Me.Picture3, Picture3.Picture
    End If
    End If
    Call Deconnect
    
End Sub

Private Sub Command1_Click()
    Me.Picture1.AutoRedraw = True
    CommonDialog1.ShowOpen
        pic = CommonDialog1.FileName
        Picture1.Picture = LoadPicture(CommonDialog1.FileName)
        ResizePicture Me.Picture1, Picture1.Picture
        
End Sub
Private Sub Command2_Click()
Me.Picture2.AutoRedraw = True
    CommonDialog1.ShowOpen
        pic2 = CommonDialog1.FileName
        Picture2.Picture = LoadPicture(CommonDialog1.FileName)
        ResizePicture Me.Picture2, Picture2.Picture
End Sub
Private Sub Command3_Click()
Me.Picture3.AutoRedraw = True
    CommonDialog1.ShowOpen
        pic3 = CommonDialog1.FileName
        Picture3.Picture = LoadPicture(CommonDialog1.FileName)
        ResizePicture Me.Picture3, Picture3.Picture
End Sub
Private Sub ResizePicture(pBox As PictureBox, pPic As Picture)
      Dim lWidth      As Single, lHeight    As Single
      Dim lnewWidth   As Single, lnewHeight As Single
  
          'Clear the Picture in the PictureBox
          pBox.Picture = Nothing
          'Clear the Image  in the Picturebox
          pBox.Cls
  
          'Get the size of the Image, but in the same Scale than the scale used by the PictureBox
          lWidth = pBox.ScaleX(pPic.Width, vbHimetric, pBox.ScaleMode)
          lHeight = pBox.ScaleY(pPic.Height, vbHimetric, pBox.ScaleMode)
  
          'If image Width > pictureBox Width, resize Width
          If lWidth > pBox.ScaleWidth Then
              lnewWidth pBox.ScaleWidth              'new Width PB width
              lHeight = lHeight * (lnewWidth / lWidth) 'Risize Height keeping proportions
          Else
              lnewWidth = lWidth                       'If not, keep the original Width value
          End If
  
          'If the image Height > The pictureBox Height, resize Height
          If lHeight > pBox.ScaleHeight Then
              lnewHeight pBox.ScaleHeight                   'new Height PB Height
              lnewWidth = lnewWidth * (lnewHeight / lHeight)  'Risize Width keeping proportions
          Else
              lnewHeight = lHeight                            'If not, use the same value
          End If
  
          'add resized and centered to Picturebox
          pBox.PaintPicture pPic, (pBox.ScaleWidth - lnewWidth) / 2, _
                                  (pBox.ScaleHeight - lnewHeight) / 2, _
                                  lnewWidth, lnewHeight
  
          'Update the Picture with the new image if you need it
          Set pBox.Picture = pBox.Image
  
      End Sub


Private Sub modifica_Click()
'Testez campurile
If codpanou.Text = "" Then
    MsgBox "Nu ati completate codul fetei !", vbInformation + vbOKOnly, "Err"
    codpanou.SetFocus
    
ElseIf Combo1.Text = "" Then
    MsgBox "Nu ati ales tipul fetei!", vbInformation + vbOKOnly, "Err"
    Combo1.SetFocus
    
ElseIf Combo3.Text = "" Then
    MsgBox "Iluminat DA sau NU!", vbInformation + vbOKOnly, "Err"
    Combo3.SetFocus

ElseIf Combo4 = "" Then
    MsgBox "Construit DA sau NU!", vbInformation + vbOKOnly, "Err"
    Combo4.SetFocus
    
Else

mobjrec.SQL = "select * from PANOURI where IdPanou=" & IDPanou.Text
    mobjrec.RSOpen
    With rst
        .Fields!codpanou = "" & codpanou.Text
        .Fields!Judet = 0 + Combo5.ItemData(Combo5.ListIndex)
        .Fields!Localitate = 0 + Combo7.ItemData(Combo7.ListIndex)
        .Fields!adresa = "" & adresa.Text
        .Fields!Zona = "" & Text2.Text
        .Fields![Detalii locatie] = "" & Text3.Text
        .Fields!Tip = 0 + Combo1.ItemData(Combo1.ListIndex)
        .Fields!Dimensiuni = "" & Text1.Text
        .Fields!Iluminat = 0 + Combo3.ItemData(Combo3.ListIndex)
        .Fields!Construit = 0 + Combo4.ItemData(Combo4.ListIndex)
        .Fields!Poza = pic
        .Fields!Poza2 = pic2
        .Fields!Poza3 = pic3
        .Update
    End With
    mobjrec.Class_Terminate
    Call cancel_Click
     
    Call Form_Load
   
    MsgBox "Informatiile despre panou au fost modificate!"
    Call LoadFlexGrid
   
End If
End Sub

Private Sub sterg_Click()
On Error GoTo err
If (MsgBox("Confirmati stergerea  [" & ListC.TextMatrix(ListC.RowSel, 1) & "]?", vbYesNo + vbQuestion, "Stergere") = vbYes) Then
    
    Call Connect
    mobjrec.SQL = " select * from INCHIRIERI WHERE INCHIRIERI.DataSfContract># " & Format(Now, "dd-mmm-yy") & " # "
    mobjrec.RSOpen
    If (rst.RecordCount > 0) Then
        MsgBox "Inca inchiriat !!!", vbInformation, "Eroare"
        Call Deconnect
    Else
    
    Call Connect
    mobjrec.SQL "Delete from PANOURI where IDPanou " & ListC.TextMatrix(ListC.RowSel, 1) & ";"
    mobjrec.RSOpen
    Call Deconnect
    ListC.RemoveItem ListC.RowSel

End If
End If
GoTo fin
err:
   'MsgBox " Eroare la stergere din baza de date", vbInformation, "Eroare"
fin:
End Sub



Merci
Messages postés
16
Date d'inscription
mercredi 21 décembre 2005
Statut
Membre
Dernière intervention
17 janvier 2010

J'ai trouvé l'erreur, mais maintenant j'ai un autre problème. En Poza, Poza2, Poza3 j'ai sauvé link pour la photo.
J'essaie de modifier les informations sur un paneaux.
Lorsque j'ajoute une photo il se passe bien, mais lorsque je tente de modifier toute autres fileds , pas la photo, la photo actuelle disparaître,va vide.


quelqu'un peut-il m'aider?

Merci!!!
Messages postés
14008
Date d'inscription
samedi 29 décembre 2001
Statut
Modérateur
Dernière intervention
28 août 2015
81
Beaucoup de code, peu de commentaire, mauvaise indentation des structures = difficile à lire.
Est-ce que ce que tu appelles une "modification" se trouve dans la Sub modifica_Click ?
Dans cette Sub, tu fais un Select dans rst puis tu rerentres des infos dedans.
Que se passe t-il dans ta classe clsMyADOConn ?
Nous, on ne le sait pas.
Est-ce qu'elle s'occupe d'afficher le résultat, d'envoyer Poza, Poza2, Poza3 dans pic, pic2 et pic3 ?
Pense à ajouter un DoEvents de temps en temps pour laisser le temps au système de faire les affichages.

D'autre part : futur bug :
INCHIRIERI.DataSfContract># " & Format(Now, "dd-mmm-yy") & " # "
...........................^................................^.... = Espaces en trop
INCHIRIERI.DataSfContract>#" & Format(Now, "dd-mmm-yy") & "# "

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)