Inserer données dans une table

Signaler
Messages postés
5
Date d'inscription
lundi 16 juin 2008
Statut
Membre
Dernière intervention
21 octobre 2008
-
Messages postés
56
Date d'inscription
lundi 8 septembre 2008
Statut
Membre
Dernière intervention
29 octobre 2010
-
slt chers amis,j'ai besoin d'aide pour charger automatiquement et periodiquement ma table (alarm_indic) à partir d'un fichier texte bloc note.je programme en vb.net et ma base de données est en sql server.
chemin fichier:G:\indic_QOS\alarm

merci d'avance



voici mon code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("ça commence!")
Dim ligne As String
Dim indice() As String
Dim heure_c As String = TimeString
Dim date_c As Date = Today
Dim sep As Char = ";"
Dim dat5 As String
Dim dat21 As String
Dim sep1 As Char = " "
Dim specifiqp As String
'Dim pas As Integer
Dim alarmid, duration As String
Dim con As New SqlConnection
Dim dur As TimeSpan
Dim cmd As SqlCommand = con.CreateCommand
Dim namesite As String

Dim Readerline As StreamReader = New StreamReader(TextBox1.Text)
con.ConnectionString = ("workstation id=qos;packet size=4096;integrated security=SSPI;data source=localhost;persist security info=False;initial catalog=indic_O&M")
con.Open()
Try


Do
alarmid = "Test: "
ligne = Readerline.ReadLine()
indice = ligne.Split(sep)
Console.Out.WriteLine(indice.Length)
'MsgBox(indice.Length)
If indice.Length = 28 Then
'MsBox("ça commence!!!")
'MsgBox(indice(5).Split(" ")(1))
dat5 = indice(5).Split("+")(0) & " " & indice(5).Split(" ")(1)
'MsgBox(dat5)
dat21 = indice(21).Split("+")(0) & " " & indice(21).Split(" ")(1)
dur = CType(dat21, DateTime).Subtract(CType(dat5, DateTime))
duration = dur.Days & ":" & dur.Hours & ":" & dur.Minutes & ":" & dur.Seconds
specifiqp = (indice(7).Split("(")(1)).Split(")")(0)

namesite = (indice(18).Split("/")(0).Substring(1, (indice(18).Split("/")(0).Length - 2)))
'duration = duration + ":" + dur.Seconds
'cmd.CommandText = "insert INTO alarm_indic(alarmid, moc, moi, eventType,sto,operatname,dhd,dhf,duree,datedeb,datefin,procause,cristicite,hdeb,hfin)values('" & indice(1) & "','" & indice(2) & "','" & indice(3) & "','" & indice(4) & "','josiane','" & indice(20) & "','" & indice(5) & "','" & indice(23) & "','" & duration & "','" & indice(5).Split(" ")(2) & "','" & indice(23).Split(" ")(2) & "','" & indice(6) & "','" & indice(8) & "','" & indice(5).Split(" ")(1) & "','" & indice(23).Split(" ")(1) & "')"
'cmd.CommandText = "insert INTO alarm_indic(alarmid, moc, moi,sto,operatname,dhd,dhf,duree,datedeb,datefin,procause,cristicite,hdeb,hfin)values('" & indice(1) & "','" & indice(2) & "','" & indice(3) & "','josiane','" & indice(18) & "','" & indice(5).Substring(15, 8) & "','" & indice(22).Substring(15, 8) & "','" & duration & "','" & indice(5).Split(" ")(2) & "','" & indice(22).Split(" ")(2) & "','" & indice(6) & "','" & indice(8) & "','" & indice(5).Substring(0, 8) & "','" & indice(22).Substring(0, 8) & "')"
cmd.CommandText = "insert INTO alarm_indic(alarmid, moc, moi,sto,eventType,operatname,dhd,dhf,duree,datedeb,datefin,procause,cristicite,hdeb,hfin,specifiqprb)values('" & indice(1) & "','" & indice(2) & "','" & indice(3) & "','josiane','" & indice(4) & "','" & namesite & "','" & dat5 & "','" & dat21 & "','" & duration & "','" & dat5.Split(" ")(1) & "','" & dat21.Split(" ")(1) & "','" & indice(6) & "','" & indice(8) & "','" & dat5.Split(" ")(0) & "','" & dat21.Split(" ")(0) & "','" & specifiqp & "')"
cmd.ExecuteNonQuery()
'MsgBox("ça commence!")
'MsgBox("ça commencennnn!")
'alarmid = alarmid + indice(1) + " ; " + indice(2) + " ; " + indice(3) + " ; " + indice(5) + " ; " + indice(6) + " ; " + indice(8) + " ; " + indice(20) + " ; " + indice(23)
Else
'If indice.Length < 29 Then
'Else
'pas = indice.Length - 29
'alarmid = alarmid + indice(1) + " ; " + indice(2) + " ; " + indice(3) + " ; " + indice(5) + " ; " + indice(6) + " ; " + indice(8) + " ; " + indice(20 + pas) + " ; " + indice(23 + pas)
'End If
End If
Console.Out.WriteLine(indice.Length)
Loop Until ligne Is Nothing
Console.Out.WriteLine("***Fin***")

' MsgBox(ex.Message)
Readerline.Close()
con.Close()
MsgBox("c'est fini")
Catch ex As Exception
End Try

End Sub

1 réponse

Messages postés
56
Date d'inscription
lundi 8 septembre 2008
Statut
Membre
Dernière intervention
29 octobre 2010

hummmm...c'est quoi ton soucis...

qui m'aime me suive...quoi personne...><

et une victoire de plus pour Mr canard