Bonjour,

Je bosse sur vb.net 2003, je fais une application dans laquelle j'affiche des tables venant d'une base SQL.

J'arrive a faire a peu près tout ce que je veux sauf une seule chose :

En fait je visualise des emissions TV (Horaires, Nom, Genre...etc).

J'ai un champs "A enregistrer?", qui est par defaut a 0, et que je passe à 1 s'il faut ajouter cette emission. ensuite, les emissions dont ce champs vaut 1 et qui a été modifié, je les mets dans une autre table. Jusque la tout fonctionne. Le pb c'est que je modifie mon dataset (lorsque je change le "A enregistrer?"), et je voudrais que ça modifie ma table d'origine.

J'ai donc essayé d'utiliser une fonction UPDATE mais ça ne marche pas, j'ai la requete SQL qui ne marche pas... elle ne veut pas s'executer...

Si quelqu'un pouvait me dire s'il y a un problème....

Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
 
    Private Sub miValiderChgnts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miValiderChgnts.Click
        Dim SqlConnectionObj As SqlClient.SqlConnection
        Dim SqlCommandObj As SqlClient.SqlCommand
        Dim SqlDataAdapterObj As SqlClient.SqlDataAdapter
        Dim SqlRequestString As String
        Dim SqlRequestString2 As String
 
        Try
            SqlConnectionObj = New SqlClient.SqlConnection(GetSqlConnectionString("POSTE03\POSTEDEV", "sa", "Spirou", "AudioVideo", "BaseDeDonnes"))
            SqlConnectionObj.Open()
 
            SqlCommandObj = New SqlClient.SqlCommand
            SqlCommandObj.Connection = SqlConnectionObj
            SqlCommandObj.CommandType = CommandType.Text
            SqlCommandObj.CommandTimeout = 60
 
            For Each row As DataRow In DataSetAvailable.Tables("OccurencesEmissions").Select("IsRecorded = TRUE", "", DataViewRowState.ModifiedCurrent)
                Dim value As Byte = 0
                MessageBox.Show(row("IsRecorded").ToString)
                If row("IsRecorded").ToString = "True" Then
                    value = 1
                End If
                SqlRequestString = "INSERT INTO Recorded" & _
                                    "(IdAvailable, Chaine, Canal, Name, StartTime, EndTime)" & _
                                    "VALUES" & _
                                    "(" & row("IdAvailable").ToString & ", '" & row("Chaine").ToString & "' , " & row("Canal").ToString & ",'" & row("Name").ToString & "', '" & row("StartTime").ToString & "', '" & row("EndTime").ToString & "')"
 
                SqlRequestString2 = "UPDATE Available" & _
                                    " SET IsRecorded = " & value.ToString
 
                SqlCommandObj.CommandText = SqlRequestString
                SqlCommandObj.ExecuteNonQuery()
 
                SqlCommandObj.CommandText = SqlRequestString2
                SqlCommandObj.ExecuteNonQuery()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            If Not SqlConnectionObj Is Nothing Then
                SqlConnectionObj.Close()
                SqlConnectionObj.Dispose()
                SqlConnectionObj = Nothing
            End If
        End Try
    End Sub