Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim Conn As New OleDbConnection(strConnection)
Dim Comm As New OleDb.OleDbCommand()
Conn.Open()
Dim intNumRows As Integer
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Dim strSQL As String
strSQL = "SELECT count(*) from [GROUP_USERS] gu WHERE gu.[GROUP_USER_ID] = '" & Me.DataGridView1.Item(2, i).Value.ToString() & "' "
Comm = New OleDbCommand(strSQL, Conn)
intNumRows = Comm.ExecuteScalar()
If intNumRows > 0 Then
'MessageBox.Show("มี USER นี้แล้ว.")
'Else
Dim strSQL2 As String
strSQL2 = "INSERT INTO GROUP_USERS ([GROUP_USER],[USER_NAME],[Create_User],[Create_Date]) " &
" VALUES " &
" ('" & Me.TextBox1.Text & "','" & Me.DataGridView1.Item(1, i).Value.ToString() & "', '" & Label6.Text & "' , getdate() )"
Comm = New OleDbCommand
With Comm
.Connection = Conn
.CommandText = strSQL2
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
MessageBox.Show("เพิ่ม USER นี้แล้ว.")
Else
Dim strSQL3 As String
strSQL3 = ""
Me.DataView()
End If
End Sub
If intNumRows > 0 Then
'MessageBox.Show("มี USER นี้แล้ว.")
'Else
Dim strSQL2 As String
strSQL2 = "INSERT INTO GROUP_USERS ([GROUP_USER],[USER_NAME],[Create_User],[Create_Date]) " &
" VALUES " &
" ('" & Me.TextBox1.Text & "','" & Me.DataGridView1.Item(1, i).Value.ToString() & "', '" & Label6.Text & "' , getdate() )"
Comm = New OleDbCommand
With Comm
.Connection = Conn
.CommandText = strSQL2
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
MessageBox.Show("เพิ่ม USER นี้แล้ว.")
Else
Dim strSQL3 As String
strSQL3 = " Update อะไรก็ว่ากันไป"
Comm = New OleDbCommand
With Comm
.Connection = Conn
.CommandText = strSQL3
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
MessageBox.Show("Update USER นี้แล้ว.")
Me.DataView()
End If