01.
Private
Sub
Button4_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button4.Click
02.
connect()
03.
04.
Dim
num = DataGridView1.RowCount
05.
num = num - 1
06.
For
i
As
Integer
= 0
To
num
07.
Dim
c1 = DataGridView1.Rows(i).Cells(0).Value
08.
Dim
c2 = DataGridView1.Rows(i).Cells(1).Value
09.
Dim
c3 = DataGridView1.Rows(i).Cells(2).Value
10.
Dim
c4 = DataGridView1.Rows(i).Cells(3).Value
11.
Dim
c5
As
String
=
Date
.Now.ToString(
"yyyyMMdd"
)
12.
Dim
c6
As
String
=
Date
.Now.ToString(
"hhmmss"
)
13.
Dim
c7
As
String
=
Date
.Now.ToString(
"yyyyMMdd"
)
14.
Dim
c8
As
String
=
Date
.Now.ToString(
"hhmmss"
)
15.
sql =
String
.Format(
"Select Count (*) as QTY from Import where Country"
= c1
And
"[First Date]"
= c2
And
"[Final Date]"
= c3)
16.
17.
18.
19.
If
"QTY"
<> 0
Then
20.
21.
sql =
String
.Format(
"Update Import SET Country "
= c1,
"[First Date]"
= c2,
"[Final Date] "
= c3,
"[Exchange Rate]"
= c4,
"[Update Date]"
= c7,
"[Update Time]"
= c8)
22.
Else
23.
sql =
String
.Format(
"Insert into import values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')"
,
24.
c1, c2, c3, c4, c5, c6, c7, c8)
25.
End
If
26.
cmd =
New
SqlCommand(sql, cn)
27.
cmd.ExecuteNonQuery()
28.
Next
29.
MsgBox(
"Saved successfully"
)
30.
End
Sub