[VB.NET] Index hors limites
I
Bonjour cher amis
L'index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection.
Public Class Catalogue
Dim i As Integer
' \\\\\\\\\\\ technique de mouver la form //////////////
#Region "Global Variables"
Dim point As New System.Drawing.Point
Dim x, y As Integer
#End Region
#Region "GUI"
Private Sub Catalogue_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
point = Control.MousePosition
point.X = point.X - (x)
point.Y = point.Y - (y)
Me.Location = point
End If
End Sub
Private Sub Catalogue_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
x = Control.MousePosition.X - Me.Location.X
y = Control.MousePosition.Y - Me.Location.Y
End Sub
#End Region
Private Sub Catalogue_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.MdiParent = Menu1
remplir_dgv_cat()
remplir_cbo_famille()
End Sub
'Sub sup_P(ByVal Code_pdt As String)
' Code_pdt = dgv_cat.SelectedRows.Count
' Dim rsql As String = "delete from Catalogue where code_pdt='" & Code_pdt & "'"
' cmd = New SqlCommand(rsql, cn)
' With cmd.Parameters
' .AddWithValue("@Code_pdt ", Code_pdt)
' End With
' Try
' cmd.ExecuteNonQuery()
' Catch ex As Exception
' MessageBox.Show(ex.Message)
' Finally
' cmd.Dispose()
' MsgBox("votre suppression a été réalisée avec succès")
' End Try
'End Sub
Sub remplir_dgv_cat()
Dim Rsql As String = "Select*From Catalogue "
cmd = New SqlCommand(Rsql, cn)
dr = cmd.ExecuteReader
dgv_cat.Rows.Clear()
While dr.Read
dgv_cat.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5), dr(6), dr(7), dr(8), dr(9))
End While
cmd.Dispose()
dr.Close()
End Sub
' \\\\\\\\\\ chargement cbo famille /////////////
Sub remplir_cbo_famille()
Dim Rsql As String = "Select*From famille order by famille asc"
cmd = New SqlCommand(Rsql, cn)
dr = cmd.ExecuteReader
Famille.Items.Clear()
While dr.Read
Famille.Items.Add(dr(0))
End While
cmd.Dispose()
dr.Close()
End Sub
' \\\\\\\\\\ proccudre ajout/////////////
Sub ajouter_produit(ByVal Code_pdt As String, ByVal Code_barre As String, ByVal Libelle As String, ByVal CUMP As Decimal, ByVal Prix_Public As Decimal, ByVal Prix_revendeur As Decimal, ByVal Qte_stock As Double, ByVal Qte_dispo As Double, ByVal Qte_Critique As Double, ByVal famille As String)
Dim rsql As String = ""
'rsql = "Select Code_pdt from Catalogue where code_pdt='" & Code_pdt & "'"
'cmd = New SqlCommand(rsql, cn)
'dr = cmd.ExecuteReader
'If dr.Read Then
' MessageBox.Show("Ce Produit il existe déjà")
' Exit Sub
'End If
'cmd.Dispose()
'dr.Close()
rsql = " Insert into Catalogue(Code_pdt,Code_barre,Libelle,CUMP,Prix_Public,Prix_revendeur,Qte_stock,Qte_dispo,Qte_Critique,famille) values(@Code_pdt,@Code_barre,@Libelle,@CUMP,@Prix_Public,@Prix_revendeur,@Qte_stock,@Qte_dispo,@Qte_Critique,@famille)"
cmd = New SqlCommand(rsql, cn)
With cmd.Parameters
.AddWithValue("@Code_pdt", Code_pdt)
.AddWithValue("@Code_barre", Code_barre)
.AddWithValue("@Libelle", Libelle)
.AddWithValue("@CUMP", CUMP)
.AddWithValue("@Prix_Public", Prix_Public)
.AddWithValue("@Prix_revendeur", Prix_revendeur)
.AddWithValue("@Qte_stock", Qte_stock)
.AddWithValue("@Qte_dispo", Qte_dispo)
.AddWithValue("@Qte_Critique", Qte_Critique)
.AddWithValue("@famille", famille)
End With
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cmd.Dispose()
End Try
End Sub
' \\\\\\\\\\\\\\\\\\\\button enregistrer////////////
Private Sub bt_enrg_Click(sender As Object, e As EventArgs) Handles bt_enrg.Click
'Try
For i As Short = 0 To dgv_cat.Rows.Count - 2
With dgv_cat
ajouter_produit(.Item(i, 0).Value, .Item(i, 1).Value, .Item(i, 2).Value, .Item(i, 3).Value, .Item(i, 4).Value, .Item(i, 5).Value, .Item(i, 6).Value, .Item(i, 7).Value, .Item(i, 8).Value, .Item(i, 9).Value)
End With
Next
'Catch ex As Exception
' MessageBox.Show(ex.Message)
'Finally
'End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub bt_sup_p_Click(sender As Object, e As EventArgs) Handles bt_sup_p.Click
'sup_P(Column1.Selected.ToString)
End Sub
End Class
le code du milieu représente mon probleme
Merci pour votre aide
mes images
I
aucun réponse mes amies
essaie de joindre un fichier exemple avec ton message.