Hi, i would like to share you my problem in order to get solution `cause i gonna be crazy :(
Actualy when i do click to insert button in my form i get this error:

the strange is when i close this window and i do click again the insert button the record is successfully added the the database :(
here my insert code (the necessary because it`s so long):

Try
               
                'build sql requests
                Dim sqlQRY1 As String = "INSERT INTO AUDIO  Values ('" + nomAudio + "')"
                Dim sqlQRY2 As String = "INSERT INTO [IMAGE] Values ('" + nomImage + "')"
                Dim sqlQRY3 As String = "INSERT INTO [TEST](Int_Exa,Rep_Correctes,Nom_Aud,Nom_Img)  Values ('" + nomExamen + "','" + repTest + "','" + nomAudio + "','" + nomImage + "')"
                'ouvrir la connexion
                myConnexion.Open()
               
                'build commands
                Dim cmd1 As OleDbCommand = New OleDbCommand(sqlQRY1, myConnexion)
                Dim cmd2 As OleDbCommand = New OleDbCommand(sqlQRY2, myConnexion)
                Dim cmd3 As OleDbCommand = New OleDbCommand(sqlQRY3, myConnexion)
                'requests execution
                cmd1.ExecuteNonQuery()
                cmd2.ExecuteNonQuery()
                cmd3.ExecuteNonQuery()

                MsgBox("Test successfully addes.", MsgBoxStyle.Information)
                'closing connexion
                myConnexion.Close()
                
            Catch ex As Exception
                MsgBox(ex.ToString)
            Finally
                myConnexion.Close()
            End Try

i would ask why in first click he show me error but in the second it worked although it`s the same operation, the same form without changing anything in his components and fields . thx in advance.

Without knowing the following, it is impossible to tell you what's going on:

1. The values and types of your variables: nomAudio, nomImage, nomExamen and repTest
2. What exactly is line 119

What also might help is knowing the structure of your database. At the tables AUDIO, [IMAGE], and [TEST] and their dependencies.

Hi, my variables nomAudio, nomImage, nomExamen and repTest have all String type.
the line 119 is this (i tried to work without try catch and the debogger stopped in this line, so i think it`s the 119 line):

System.IO.File.Copy(imageToCopy, newImage)

and for my dataBase structure:

hope this help, thanks in advance ;)

salut
fais attention a ce qu'il n'ya pas de caractere illegaux dans imageToCopy ou newImage
des caractere comme :\/<>?|*"
moi je pense que tu as une " quelque part ;)
et c'est myConnection et non pa myConnexion :p

Hi, i have checked the name of all the images, there is no special characters from your list :\/<>?|*", all the image`s names are composed of alphanumeric characters. besides i have a function which have the job to return a new name every time i add an image or audio, here is the code of this function:

Module Module1
    'les 2 tableaux déclarés ci-dessous sert pour la fonction calculerNom

    'un tableau contiendra les chiffres de 0 à 9
    Public tabInt(10) As Integer

    'un tableau contiendra les lettres de l`alphabet
    Public tabChar(26) As Char

    'fonction pour calculer un nouveau nom a partir d`un nom donné

    Public Function calculerNom()
        Dim i As Integer
        'initialisation des élèments du tabInt 
        For i = 0 To 9
            tabInt(i) = i
        Next i
        'initialisation des élèments du tabChar
        tabChar(0) = "A"
        tabChar(1) = "B"
        tabChar(2) = "C"
        tabChar(3) = "D"
        tabChar(4) = "E"
        tabChar(5) = "F"
        tabChar(6) = "G"
        tabChar(7) = "H"
        tabChar(8) = "I"
        tabChar(9) = "J"
        tabChar(10) = "K"
        tabChar(11) = "L"
        tabChar(12) = "M"
        tabChar(13) = "N"
        tabChar(14) = "O"
        tabChar(15) = "P"
        tabChar(16) = "Q"
        tabChar(17) = "R"
        tabChar(18) = "S"
        tabChar(19) = "T"
        tabChar(20) = "U"
        tabChar(21) = "V"
        tabChar(22) = "W"
        tabChar(23) = "X"
        tabChar(24) = "Y"
        tabChar(25) = "Z"
        'une variable de la classe Random
        Dim A1 As New Random()
        Dim A2 As New Random()
        Dim chiffreChoisi As Integer 'indique l`indice aléatoire du chiffre à extraire
        Dim lettreChoisi As Integer 'indique l`indice aléatoire du caractère à extraire
        'le nouveau nom 
        Dim nouveauNom As String = ""
        For i = 0 To 5
            chiffreChoisi = A1.Next(0, 10)
            nouveauNom = nouveauNom + tabInt(chiffreChoisi).ToString
            lettreChoisi = A2.Next(0, 27)
            nouveauNom = nouveauNom + tabChar(lettreChoisi).ToString
        Next
        Return nouveauNom
    End Function
End Module

i don`t understand why the program doesn`t accept the first time but in second time every think go correctly :(

i forget one thing, you were right, there is special characters in the imageToCopy String, example:
D:\presta\Mahraz\Serie-02\S02Q04.jpg
so there is ":"
how should i correct this, VB need the old path wich is imageToCopy string, if i delete the ":" from the imageToCopy the path become unknown, is there any solution??

the ":" in D:\presta\Mahraz\Serie-02\S02Q04.jpg is not an illegal char !!
in this case it would be
D:\presta\Mahraz\Serie-02\S02:Q04.jpg
you see ?
you can make a breakpoint at line 119 and check ! maybe you're missing something.

Hi, i tried the breakpoint, he stopped in this line:

System.IO.File.Copy(imageToCopy, newImage)

as you said :)
the problem certainly comes from this line but how to prevent this error still the problem ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.