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
| Imports System.Data.SqlClient
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim StrCon As SqlConnection = Nothing
Try
StrCon = New SqlConnection("data source=MADA; initial catalog= DATAOBERGE;User ID=sa;Password=123456789;")
Using DepCom As SqlCommand = New SqlCommand("Select * From TableOberge", StrCon)
StrCon.Open()
Using DepAdap As SqlDataAdapter = New SqlDataAdapter(DepCom)
Dim DepDT As DataTable = New DataTable
DepAdap.Fill(DepDT)
DataGridView1.DataSource = DepDT
Dim CurrentBs As BindingSource = New BindingSource()
CurrentBs.DataSource = DepDT
DataGridView2.DataSource = CurrentBs
CurrentBs.Filter = String.Format("[Date_IN] = #{0}# AND [Hour_IN] >= #{1}#", DateTime.Now.Date, DateTime.Now.Hour)
End Using
StrCon.Close()
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
If StrCon IsNot Nothing Then
If StrCon.State = ConnectionState.Open Then
StrCon.Close()
End If
StrCon.Dispose()
End If
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using Command As New SqlCommand With {.Connection = StrCon}
With Command.Parameters
Command.CommandText = "INSERT INTO [TABLEOBERGE] ([ID], [FIRSTNAME], [PHONE], [ADRESSE], [DATE_OUT], [HOUR_OUT], [DATE_IN], [HOUR_IN]) VALUES (@ID, @FIRSTNAME, @PHONE, @ADRESSE, @DATE_OUT, @HOUR_OUT, @DATE_IN, @HOUR_IN)"
.AddWithValue("@ID", SqlDbType.Int).Value = TextBox1.Text
.AddWithValue("@FIRSTNAME", SqlDbType.NVarChar).Value = TextBox2.Text
.AddWithValue("@PHONE", SqlDbType.NVarChar).Value = TextBox3.Text
.AddWithValue("@ADRESSE", SqlDbType.NVarChar).Value = TextBox4.Text
.AddWithValue("@DATE_OUT", SqlDbType.Date).Value = TextBox5.Text
.AddWithValue("@HOUR_OUT", SqlDbType.Time).Value = TextBox6.Text
.AddWithValue("@DATE_IN", SqlDbType.Date).Value = TextBox7.Text
.AddWithValue("@HOUR_IN", SqlDbType.Time).Value = TextBox8.Text
End With
If StrCon.State = ConnectionState.Closed Then StrCon.Open()
If Command.ExecuteNonQuery() = 1 Then
MsgBox("SUCCED ADD", MsgBoxStyle.MsgBoxRtlReading, "SUCCES")
Else
MsgBox("ERROR FATAL", MsgBoxStyle.MsgBoxRtlReading, "ERROR")
End If
StrCon.Close()
End Using
End Sub
End Class |
Partager