Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinL1.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= E:\Data.MDB;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
ReadMyData(Cnnstring)
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
Cnn.ConnectionString = Cnnstring
SqlSelect = "Select Count(*) From [computers] Where [roomcode]=@roomcode And [computercode]=@computercode And [status]=@status"
Dim OleCommand As OleDbCommand = New OleDbCommand(SqlSelect, Cnn)
OleCommand.Parameters.Add("@status", OleDbType.VarChar).Value = 0
Cnn.Open()
Dim LoginSuccess As Integer = CInt(OleCommand.ExecuteScalar())
Cnn.Close()
If LoginSuccess = 0 Then
Dim st As Integer = 1
With Conn
Conn = New OleDb.OleDbConnection(strConnection)
Conn.Open()
End With
sqlSave = "INSERT INTO operation([roomcode],[computercode],[ID],[sttime],[status])"
sqlSave &= "VALUES('" & LO1.Text & "','" & Label5.Text & "','" & TextBoxID.Text & "','" & dtpOut.Text & "','" & st & "')"
With com
.CommandText = sqlSave
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
If MsgBox("ป้อนข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Question + MsgBoxStyle.OkOnly) = MsgBoxResult.Yes Then
End If
Else
MessageBox.Show("ไม่ว่าง", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Imports System.Data.OleDb
Imports System.Data
Public Class Systems
Dim frmProjectVB As New ProjectVB_Final
Const DATABASE_FILE As String = "E:\Data.MDB"
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DATABASE_FILE
Dim Conn As New OleDb.OleDbConnection(strConnection)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim Cnn As New OleDbConnection(Cnnstring)
Dim dv As DataView
Dim sqlSave As String
Dim Cnnstring As String
Dim n1 As Integer
Dim SqlSelect As String
Dim com As New OleDb.OleDbCommand
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinL1.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= E:\Data.MDB;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
ReadMyData(Cnnstring)
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
Cnn.ConnectionString = Cnnstring
SqlSelect = "Select From [computers] Where [status]=@status"
Dim OleCommand As OleDbCommand = New OleDbCommand(SqlSelect, Cnn)
OleCommand.Parameters.Add("@status", OleDbType.Integer).Value = 0
Cnn.Open()
Dim LoginSuccess As Integer = CInt(OleCommand.ExecuteScalar())
Cnn.Close()
If LoginSuccess = 0 Then
Dim st As Integer = 1
With Conn
Conn = New OleDb.OleDbConnection(strConnection)
Conn.Open()
End With
sqlSave = "INSERT INTO operation([roomcode],[computercode],[ID],[sttime],[status])"
sqlSave &= "VALUES('" & LO1.Text & "','" & Label5.Text & "','" & TextBoxID.Text & "','" & dtpOut.Text & "','" & st & "')"
With com
.CommandText = sqlSave
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
If MsgBox("ป้อนข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Question + MsgBoxStyle.OkOnly) = MsgBoxResult.Yes Then
End If
Else
MessageBox.Show("ไม่ว่าง", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Public Class Systems
Dim frmProjectVB As New ProjectVB_Final
Const DATABASE_FILE As String = "E:\Data.MDB"
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DATABASE_FILE
Dim Conn As New OleDb.OleDbConnection(strConnection)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim Cnn As New OleDbConnection(Cnnstring)
Dim dv As DataView
Dim up As String
Dim sqlSave As String
Dim Cnnstring As String
Dim n1 As Integer
Dim SqlSelect As String
Dim com As New OleDb.OleDbCommand
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinL1.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= E:\Data.MDB;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
ReadMyData(Cnnstring)
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
Cnn.ConnectionString = Cnnstring
SqlSelect = "Select * From [computers] Where [status]=@status"
Dim OleCommand As OleDbCommand = New OleDbCommand(SqlSelect, Cnn)
OleCommand.Parameters.Add("@status", OleDbType.Integer).Value = 1
Cnn.Open()
Dim LoginSuccess As Integer = CInt(OleCommand.ExecuteScalar())
Cnn.Close()
If LoginSuccess = 0 Then
Dim st As Integer = 1
With Conn
Conn = New OleDb.OleDbConnection(strConnection)
Conn.Open()
End With
sqlSave = "INSERT INTO operation([roomcode],[computercode],[ID],[sttime],[status])"
sqlSave &= "VALUES('" & LO1.Text & "','" & Label5.Text & "','" & TextBoxID.Text & "','" & dtpOut.Text & "','" & st & "')"
up = "UPDATE INTO computers([status])"
sqlSave &= "VALUES('" & st & "')"
With com
.CommandText = sqlSave
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
If MsgBox("ป้อนข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Question + MsgBoxStyle.OkOnly) = MsgBoxResult.Yes Then
End If
Else
MessageBox.Show("ไม่ว่าง", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub