Public Class Form2
Dim dbpath As String = IO.Path.GetDirectoryName(Application.ExecutablePath) & "\db.accdb"
Dim str As String = "provider=microsoft.ace.oledb.12.0;data source=" & dbpath
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using con As New OleDb.OleDbConnection(str)
Using cm As New OleDb.OleDbCommand("select min(t) from tb", con)
If con.State = ConnectionState.Closed Then con.Open()
If IsDBNull(CDate(cm.ExecuteScalar).ToShortTimeString) = False Then
TextBox1.Text = CDate(cm.ExecuteScalar).ToShortTimeString
End If
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using con As New OleDb.OleDbConnection(str)
Using cm As New OleDb.OleDbCommand("select max(t) from tb", con)
If con.State = ConnectionState.Closed Then con.Open()
If IsDBNull(CDate(cm.ExecuteScalar).ToShortTimeString) = False Then
TextBox2.Text = CDate(cm.ExecuteScalar).ToShortTimeString
End If
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Using con As New OleDb.OleDbConnection(str)
Using cm As New OleDb.OleDbCommand("insert into tb(t) values(@t)", con)
cm.Parameters.Clear()
cm.Parameters.AddWithValue("@tn", dt.Value)
If con.State = ConnectionState.Closed Then con.Open()
Try
cm.ExecuteNonQuery()
MsgBox("تم")
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "")
End Try
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Sub
End Class