01.
Private
Sub
btnSave_Click(sender
As
Object
, e
As
EventArgs)
Handles
btnSave.Click
02.
Dim
Conn
As
New
OleDbConnection(strConnection)
03.
Dim
Comm
As
New
OleDb.OleDbCommand()
04.
05.
Conn.Open()
06.
Dim
intNumRows
As
Integer
07.
Dim
i
As
Integer
08.
09.
i = DataGridView1.CurrentRow.Index
10.
Dim
strSQL
As
String
11.
strSQL =
"SELECT count(*) from [GROUP_USERS] gu WHERE gu.[GROUP_USER_ID] = '"
&
Me
.DataGridView1.Item(2, i).Value.ToString() &
"' "
12.
Comm =
New
OleDbCommand(strSQL, Conn)
13.
intNumRows = Comm.ExecuteScalar()
14.
15.
If
intNumRows > 0
Then
16.
17.
18.
Dim
strSQL2
As
String
19.
strSQL2 =
"INSERT INTO GROUP_USERS ([GROUP_USER],[USER_NAME],[Create_User],[Create_Date]) "
&
20.
" VALUES "
&
21.
" ('"
&
Me
.TextBox1.Text &
"','"
&
Me
.DataGridView1.Item(1, i).Value.ToString() &
"', '"
& Label6.Text &
"' , getdate() )"
22.
23.
Comm =
New
OleDbCommand
24.
With
Comm
25.
.Connection = Conn
26.
.CommandText = strSQL2
27.
.CommandType = CommandType.Text
28.
.ExecuteNonQuery()
29.
End
With
30.
MessageBox.Show(
"เพิ่ม USER นี้แล้ว."
)
31.
Else
32.
Dim
strSQL3
As
String
33.
strSQL3 =
""
34.
Me
.DataView()
35.
End
If
36.
37.
End
Sub