รายละเอียดของการตอบ ::
อันนี้โค้ด ปุ่มบันทึก ครับ
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
connect()
Dim num = DataGridView1.RowCount
num = num - 1
For i As Integer = 0 To num
Dim c1 = DataGridView1.Rows(i).Cells(0).Value
Dim c2 = DataGridView1.Rows(i).Cells(1).Value
Dim c3 = DataGridView1.Rows(i).Cells(2).Value
Dim c4 = DataGridView1.Rows(i).Cells(3).Value
Dim c5 As String = Date.Now.ToString("yyyyMMdd")
Dim c6 As String = Date.Now.ToString("hhmmss")
Dim c7 As String = Date.Now.ToString("yyyyMMdd")
Dim c8 As String = Date.Now.ToString("hhmmss")
sql = String.Format("SELECT COUNT(*) AS QTY FROM Import WHERE (Country = '" & c1 & "') AND ([First Date] = '" & c2 & "') AND ([Final Date] = '" & c3 & "')")
Dim _QTY As Integer
Using cn As New SqlConnection("connectionstring")
Using com As New SqlCommand(sql, cn)
cmd = New SqlCommand(sql, cn)
cn.Open()
_QTY = Convert.ToInt32(cmd.ExecuteScalar())
End Using
End Using
If _QTY <> 0 Then
sql = String.Format("Update Import SET Country ='" & c1 & "', [First Date] ='" & c2 & "', [Final Date] ='" & c3 & "', [Exchange Rate] = '" & c4 & "', [Update Date] = '" & c7 & "',[Update Time] ='" & c8 & "'where (Country ='" & c1 & "') AND ([First Date] ='" & c2 & "') AND ([Final Date] = '" & c3 & "')")
Else
sql = String.Format("Insert into import values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
c1, c2, c3, c4, c5, c6, c7, c8)
End If
cmd = New SqlCommand(sql, cn)
cmd.ExecuteNonQuery()
Next
' If cmd.ExecuteNonQuery() = 0 Then
'MsgBox("Please try again")
'Else
MsgBox("Saved successfully")
' End If
End Sub
ส่วน text file จะมีหลายบรรทัดซึ่งในแต่ละบรรทัดจะต้องแยกคำลงในคอลัมน์อ้ะครับ ต้องการอะไรอีกบอกนะครับ
เครื่องดื่มชูกำลัง กาแฟ เบียร์เย็นๆ ขอบคุณครับ