01.
Public
Class
MainForm
02.
Dim
objConn
As
New
SqlConnection
03.
Dim
objCmd
As
New
SqlCommand
04.
Dim
strConn, strSQL
As
String
05.
Dim
da
As
New
SqlDataAdapter
06.
Dim
dt
As
New
DataTable
07.
08.
Private
Sub
MainForm_Load(sender
As
System.
Object
, e
As
System.EventArgs)
Handles
MyBase
.Load
09.
strConn =
"Server=SWEETCHIN-PC;Database=UpCountry;Trusted_Connection=True;"
10.
objConn.ConnectionString = strConn
11.
objConn.Open()
12.
13.
strSQL =
"SELECT * FROM RepairDevice"
14.
objCmd =
New
SqlCommand(strSQL, objConn)
15.
16.
da.SelectCommand = objCmd
17.
da.Fill(dt)
18.
DataGridView1.DataSource = dt
19.
da.Update(dt)
20.
21.
objConn.Close()
22.
23.
24.
End
Sub
25.
26.
Private
Sub
btnSave_Click(sender
As
System.
Object
, e
As
System.EventArgs)
Handles
btnSave.Click
27.
strConn =
"Server=SWEETCHIN-PC;Database=UpCountry;Trusted_Connection=True;"
28.
objConn.ConnectionString = strConn
29.
objConn.Open()
30.
31.
strSQL =
"INSERT INTO RepairDevice(MR_NO,IN_Date,CE_Name,Site,Type,Device,Serial_NO,Detail,OUT_Date,Complete) values(@MR_NO,@IN_Date,@CE_Name,@Site,@Type,@Device,@Serial_NO,@Detail,@OUT_Date,@Complete)"
32.
For
i
As
Integer
= 0
To
DataGridView1.RowCount - 1
33.
If
Not
DataGridView1.Rows(i).IsNewRow
Then
34.
objCmd =
New
SqlCommand(strSQL, objConn)
35.
With
objCmd
36.
.Parameters.Add(
New
SqlParameter(
"@MR_NO"
, DataGridView1.Rows(i).Cells(0).Value))
37.
.Parameters.Add(
New
SqlParameter(
"@IN_Date"
, DataGridView1.Rows(i).Cells(1).Value))
38.
.Parameters.Add(
New
SqlParameter(
"@CE_Name"
, DataGridView1.Rows(i).Cells(2).Value))
39.
.Parameters.Add(
New
SqlParameter(
"@Site"
, DataGridView1.Rows(i).Cells(3).Value))
40.
.Parameters.Add(
New
SqlParameter(
"@Type"
, DataGridView1.Rows(i).Cells(4).Value))
41.
.Parameters.Add(
New
SqlParameter(
"@Device"
, DataGridView1.Rows(i).Cells(5).Value))
42.
.Parameters.Add(
New
SqlParameter(
"@Serial_NO"
, DataGridView1.Rows(i).Cells(6).Value))
43.
.Parameters.Add(
New
SqlParameter(
"@Detail"
, DataGridView1.Rows(i).Cells(7).Value))
44.
.Parameters.Add(
New
SqlParameter(
"@OUT_Date"
, DataGridView1.Rows(i).Cells(8).Value))
45.
.Parameters.Add(
New
SqlParameter(
"@Complete"
, DataGridView1.Rows(i).Cells(9).Value))
46.
End
With
47.
objCmd.ExecuteNonQuery()
48.
End
If
49.
MessageBox.Show(
"บันทึกข้อมูลแล้ว"
)
50.
objConn.Close()
51.
Next
52.
End
Sub
53.
End
Class