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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
Imports System.Data.SqlClient
Public Class Form2
'HAUT PARLEUR: DECLARATION EN PORTEE CLASS FORM
Private matable As DataTable
Private matabletAdapter As SqlDataAdapter
Private requeteSQL As String
Private strConnection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\DBStoreSQL14\Liste_rebuts.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
'Private strConnection As String = My.Settings.Liste_rebutsConnectionString
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'ComboBox1.Text = "bobo"
'ComboBox2.Text = "blabla"
'TextBox1.Text = "19dr2500"
'CHARGEMENT
Dim connexion As New SqlConnection(strConnection)
Try
connexion.Open()
requeteSQL = "SELECT * FROM matable"
Dim command As New SqlCommand(requeteSQL, connexion)
Try
matable = New DataTable
matabletAdapter = New SqlDataAdapter(command)
matabletAdapter.Fill(matable)
MsgBox("table chargee", vbOKOnly)
'binding ici
DataGridView1.DataSource = matable
Catch ex As Exception
MessageBox.Show(ex.ToString & "Erreur lors du chargement", "erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Catch ex As Exception
MessageBox.Show("Erreur de connexion", "Erreur", MessageBoxButtons.OK)
Me.Close()
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
Dim connexion As New SqlConnection(strConnection)
Try
connexion.Open()
Dim Reference, Designation, Sn As String
Dim Stock As Integer = 1050
Dim DateJour As Date
Reference = ComboBox1.Text
Designation = ComboBox2.Text
Sn = TextBox1.Text
DateJour = "26/12/2016"
'Dim s As String = "'" & DateJour & "','" & Reference & "','" & Designation & "','" & Sn & "','" & Stock & "'"
requeteSQL = "INSERT INTO matable(Date_Saisie,Ref,Designation,SN,stock) VALUES(" & "'" & DateJour & "','" & Reference & "','" & Designation & "','" & Sn & "','" & Stock & "'" & ")"
Dim command As New SqlCommand(requeteSQL, connexion)
Try
command.ExecuteNonQuery()
MsgBox("Fiche enregistrée", vbOKOnly)
Catch ex As Exception
MessageBox.Show(ex.ToString & "Erreur lors De l'ajout de la ligne", "erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
matable.Clear()
matabletAdapter.Fill(matable)
Catch ex As Exception
MessageBox.Show("Erreur de connexion", "Erreur", MessageBoxButtons.OK)
Me.Close()
End Try
End Sub
End Class |
Partager