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 |
Partager