Salut tout le monde
Svp Gentelman .. j'ai vraiment besoin d'aide
J'ai deux Tables
TableSection avec deux champs (SectionId de Tye Numerique - SectionNumber de Type Numerique)
TableSuppliers avec 3 champs ( SupplierID de Type Numerique - SupplierSection de Type Numerique - SupplierName de Type Text)
Dans ma Form1 j'ai TextBox1 pour recuperer Max Id dans TableSuppliers
ComboBox1 pour choisir (SectionNumber) .. ComboBox1 deja remplit par le champ (SectionNumber) du Table (TableSection) de cette facon (111-222-333-444-555-666-777-888-999-101010)
TextBox2 pour remplir le nom de Supplier
TextBox3 que je vais la remplir par un nombre fixe par exemple (5) .. Alors dans ce cas si les records inscrits dans une meme (SupplierSection) dans ma TableSuppliers il faut qu'il ne depassent pas 5.
j'enregistre mes records dans (TableSuppliers) par Button2 de cette facon :
1 111 name1
2 111 name2
3 111 name3
4 111 name4
5 111 name5
Ici le nombre (111) a atteint (5) fois .. alors je veux automatiquement lorsque je vais choisir pour le sixieme record .. dans ma ComboBox1 je serai oblige de choisir (222) jusqu'a 5 fois .. apres je serai oblige de choisir dans ComboBox1 (333) aussi uniquement 5 fois ...etc ..ou bien je serai averti par un message d'erreur que j'ai fais le mauvais choix dans ComboBox1.
Voici tout mon code :
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
Imports System.Data.OleDb
Public Class Form1
    Public constring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Database1.accdb"
    Public myconnection As New OleDbConnection(constring)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myconnection.Open()
        Dim query As String = "select * from TableSection"
        Dim command As OleDbCommand = New OleDbCommand(query, myconnection)
        Dim reader As OleDbDataReader = command.ExecuteReader()
        If reader.HasRows Then
            While reader.Read()
                ComboBox1.Items.Add(reader("SectionNumber"))
            End While
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim InfoCommand As New OleDbCommand("Select max(SupplierID) from TableSuppliers", myconnection)
        If myconnection.State = ConnectionState.Closed Then myconnection.Open()
        If InfoCommand.ExecuteScalar Is DBNull.Value Then
 
            TextBox1.Text = 1
            TextBox2.Focus()
        Else
 
            TextBox1.Text = InfoCommand.ExecuteScalar + 1
            TextBox2.Focus()
        End If
 
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim sqlQry As String = "Insert Into TableSuppliers (SupplierID, SupplierSection, SupplierName) values (@SupplierID, @SupplierSection,@SupplierName)"
        Using cmd As New OleDbCommand(sqlQry, myconnection)
            cmd.Parameters.AddWithValue("@SupplierID", TextBox1.Text)
            cmd.Parameters.AddWithValue("@SupplierSection", ComboBox1.Text)
            cmd.Parameters.AddWithValue("@SupplierName", TextBox2.Text)
            Dim SaveOk As Integer = cmd.ExecuteNonQuery()
            If SaveOk <> -1 Then
                MsgBox("record enregistre avec succes")
            End If
        End Using
    End Sub
End Class
Merci beaucoup d'avance pour l'aide
Amicalement
MADA