IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Problème d'insert into


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2006
    Messages
    505
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2006
    Messages : 505
    Par défaut Problème d'insert into
    Bonjour à tous et meilleur voeu de Noel

    Je débute avec les BD, j'essai de remplir une tbl avec des string, j'ai environ 2000 enregistrements à effectuer et j'ai le message d'erreur suivant qui me bloque, quelqu'un peut m'aider ?

    Mon code est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
            Dim Resul As Integer = Nothing
            Dim ArrayCompagnie As New ArrayList
            Dim SrComp As New StreamReader(My.Settings.MonPath & "Liste\Compagnie.txt")
            Do Until SrComp.Peek = -1
                ArrayCompagnie.Add(SrComp.ReadLine)
            Loop
            SrComp.Close()
            Dim _cn As OleDbConnection
            Dim strConnection As String = My.Settings.BourseV2ConnectionString
            _cn = New OleDbConnection(strConnection)
            Try
                _cn.Open()
            Catch ex As Exception
                Throw (New ApplicationException("L'ouverture à échoué avec une ex. de type " & ex.GetType.FullName, ex))
            End Try
     
            For Each compa As String In ArrayCompagnie
                Dim SQL As String = "SELECT Count(TblCompagnie.nom) AS CompteDeNom FROM(TblCompagnie) HAVING (((TblCompagnie.nom)=""" & compa & """));"
                Dim dr As OleDbDataReader
                Dim Cmd As New OleDbCommand
                With Cmd
                    .Connection = _cn
                    .CommandType = CommandType.Text
                    .CommandText = Sql
                End With
                dr = Cmd.ExecuteReader()
                dr.Read()
    	    'Vérifie si Doublon
                Resul = CInt(dr("CompteDeNom"))
     
                Console.WriteLine(Resul.ToString)
                If Resul = 0 Then
                    Dim Cmd2 As New OleDbCommand
                    compa = compa.Replace("'", "''")
                    Dim SQL2 As String = "INSERT INTO TblCompagnie (Nom) VALUES('" & compa & "')"
                    With Cmd2
                        .Connection = _cn
                        .CommandType = CommandType.Text
                        .CommandText = SQL2
                    End With
                    Cmd2.ExecuteNonQuery()
                End If
                compa = compa.Replace("''", "'")
            Next
            _cn.Close()
            MessageBox.Show("fini")
        End Sub
    et j'obtiens le message d'erreur suivant
    L'exception System.Data.OleDb.OleDbException n'a pas été gérée
    ErrorCode=-2147467259
    Message=Impossible d'ouvrir plus de tables.
    Source=Microsoft Access Database Engine
    StackTrace:
    à System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
    à System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
    à System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
    à System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
    à System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
    à System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
    à System.Data.OleDb.OleDbCommand.ExecuteReader()
    à Bourse.RechInfo.ToolStripButton2_Click(Object sender, EventArgs e) dans C:\Users\Mario\Documents\Visual Studio 2010\Projects\Bourse\Bourse\RechInfo.vb:ligne 952
    à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
    à System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
    à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
    à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
    à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
    à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
    à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
    à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    à System.Windows.Forms.Control.WndProc(Message& m)
    à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    à System.Windows.Forms.ToolStrip.WndProc(Message& m)
    à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    à System.Windows.Forms.Application.Run(ApplicationContext context)
    à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    à Bourse.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
    à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
    à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    à System.Threading.ThreadHelper.ThreadStart()
    InnerException:
    Merci de votre aide

  2. #2
    Membre expérimenté Avatar de DarkMolo
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    207
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Maroc

    Informations forums :
    Inscription : Juillet 2006
    Messages : 207
    Par défaut
    Salut,

    Essaye en fermant ton datareader, à ce niveau :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    '...
    'Vérifie si Doublon
    Resul = CInt(dr("CompteDeNom"))
     
    'ici
    dr.Close()
     
    Console.WriteLine(Resul.ToString)
    '...

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2006
    Messages
    505
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2006
    Messages : 505
    Par défaut
    Zut j'avais en effet oublié cette ligne

    merci ça fonctionne

    Joyeuse fêtes

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. problème avec insert into
    Par ulysse031 dans le forum SQL Procédural
    Réponses: 5
    Dernier message: 29/04/2007, 15h40
  2. Problème avec INSERT INTO
    Par Armaklan dans le forum Oracle
    Réponses: 3
    Dernier message: 28/02/2007, 11h15
  3. Problème ADO - INSERT INTO
    Par unionriton dans le forum Bases de données
    Réponses: 12
    Dernier message: 14/12/2005, 14h36
  4. Réponses: 12
    Dernier message: 25/11/2005, 12h29
  5. Réponses: 3
    Dernier message: 10/05/2005, 11h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo