You are on page 1of 4

Imports System.Data.

SqlClient Public Class Form1 Public DTF As New DataTable Public DTS As New DataTable Dim dr As SqlDataReader Public Sub chargement(ByVal req As String, ByVal dt As DataTable) Dim cmd As New SqlCommand(req, cn) dt.Load(dr) End Sub Dim cn As New SqlConnection("DATA SOURCE = ISTA-1E590CA59D\SQLEXPRESS ;Initi al Catalog=stag1;Integrated Security=True")

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click cn.Open() Dim cmd As New SqlCommand(" insert into gestion(Numstag,Nomstag,Prnomstag ) values ( '" & TextBox1.Text & " ',' " & TextBox2.Text & " ',' " & TextBox3.Tex t & " ')", cn)

Try cmd.ExecuteNonQuery() MessageBox.Show("stagiare enregistr avec succs", "Gestion stagiaire", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As SqlException MessageBox.Show("Erreur", "gestion stagiaire ", MessageBoxButtons.OK , MessageBoxIcon.Error) MsgBox(ex.Message) End Try cn.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles MyBase.Load ' ComboBox1.Items.Add(1) ' ComboBox1.Items.Add(2) ' ComboBox1.Items.Add(3) Dim dt As New DataTable Dim dr As SqlDataReader

cn.Open() Dim cmd As New SqlCommand("select * from fonction", cn) dr = cmd.ExecuteReader dt.Load(dr) ComboBox2.DataSource = dt ComboBox2.DisplayMember = "nomF" ComboBox2.ValueMember = "codeF" End Sub Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Wind ows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress If Char.IsNumber(e.KeyChar) Then e.Handled = True End If End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As S ystem.EventArgs) Handles TextBox2.TextChanged End Sub Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Wind ows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress If Char.IsNumber(e.KeyChar) Then e.Handled = True End If End Sub Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As S ystem.EventArgs) Handles TextBox3.TextChanged End Sub Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Wind ows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Not Char.IsNumber(e.KeyChar) Then e.Handled = True End If End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As S ystem.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button2.Click cn.Open() Dim cmd As New SqlCommand(" delete from stag where Num = ' " & TextBox1. Text & " ' ", cn)

Try cmd.ExecuteNonQuery() MessageBox.Show("stagiare supprim avec succs", "Gestion stagiaire", Me ssageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As SqlException MessageBox.Show("Erreur", "gestion stagiaire ", MessageBoxButtons.OK , MessageBoxIcon.Error) MsgBox(ex.Message) End Try cn.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button3.Click cn.Open() Dim cmd As New SqlCommand(" update stag1 set Nomstag = ' " & TextBox2.Te xt & " ' , Prnomstag = '" & TextBox3.Text & " ' where Num = " & TextBox1.Text & " ", cn) Try cmd.ExecuteNonQuery() MessageBox.Show("stagiare enregistr avec succs", "Gestion stagiaire", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As SqlException MessageBox.Show("Erreur", "gestion stagiaire ", MessageBoxButtons.OK , MessageBoxIcon.Error) MsgBox(ex.Message) End Try cn.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button4.Click cn.Open() TextBox1.ReadOnly = True Dim cmd As New SqlCommand("Select MAX(Num) FROM stag1", cn) Dim x As Integer x = cmd.ExecuteScalar TextBox1.Text = x + 1 cn.Close()

End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, By Val e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList Dim dr As SqlDataReader cn.Open() Dim cmd As New SqlCommand(" select * from stag1 where Num= " & ComboBox1 .Text & " ", cn) dr = cmd.ExecuteReader If dr.Read Then TextBox2.Text = dr(1).ToString TextBox3.Text = dr(2).ToString End If dr.Close() cn.Close() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button5.Click Dim dt As New DataTable Dim dr As SqlDataReader cn.Open() Dim cmd As New SqlCommand("select * from stag1", cn) dr = cmd.ExecuteReader dt.Load(dr) DataGridView1.DataSource = dt dr.Close() cn.Close() End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, By Val e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged If ComboBox2.SelectedIndex > 0 Then Dim dt As New DataTable Dim dr As SqlDataReader cn.Open() Dim cmd As New SqlCommand("select * from stag1 where code fonction=" & ComboBox2.SelectedValue & " ", cn) dr = cmd.ExecuteReader dt.Load(dr) DataGridView2.DataSource = dt End If End Sub End Class http://www.startimes.com/f.aspx?t=29189727

You might also like