1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
public Class filewatch
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
fsw.EnableRaisingEvents = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
fsw.EnableRaisingEvents = False
End Sub
Private Sub fsw_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Created
Dim l As String
Dim tab As String()
Dim filename As String
Dim Conn As New System.Data.SqlClient.SqlConnection
Dim comm As New SqlClient.SqlCommand
filename = fsw.Path + "\" + e.Name
Dim i As Integer
i = FreeFile()
FileOpen(i, filename, OpenMode.Input)
Conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & "C:\Documents and Settings\Administrateur\Mes documents\Visual Studio 2005\Projects\WindowsService1\WindowsService1\Database1.mdf" & ";Integrated Security=True;User Instance=True"
Conn.Open()
While Not EOF(i)
l = LineInput(i)
tab = l.Split(" "c)
Try
comm.CommandText = "insert into Interdits (NCIN, [Nom et Prénom],Adresse,Teléphone,Statut) values ('" & tab(0) & "','" & tab(1) & "','" & tab(2) & "','" & tab(3) & "','" & tab(4) & "')"
comm.Connection = Conn
comm.ExecuteScalar()
Catch err As Exception
End Try
End While
Conn.Close()
Conn.Dispose()
FileClose(i)
Kill(filename)
End Sub
End Class |
Partager