1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Using file As New StreamReader(fileName)
Using connection As New SqlConnection(connectionString)
Using command As New SqlCommand("INSERT INTO PERSONNE(NOM, PRENOM, AGE) VALUES (@nom, @prenom, @age)", connection)
command.Parameters.Add("@nom", DbType.String)
command.Parameters.Add("@prenom", DbType.String)
command.Parameters.Add("@age", DbType.Int32)
Dim line As String = file.ReadLine()
While line IsNot Nothing
Dim parts() as String = line.Split(";")
command.Parameters("@nom").Value = parts(0)
command.Parameters("@prenom").Value = parts(1)
command.Parameters("@age").Value = Int32.Parse(parts(2))
command.ExecuteNonQuery()
line = file.ReadLine()
End While
End Using
End Using
End Using |
Partager