Vb.net datagridview update une bd ACCES

rapidozoo 4 Messages postés mardi 12 décembre 2000Date d'inscription 26 août 2011 Dernière intervention - 26 août 2011 à 05:13 - Dernière réponse : ucfoutu 18039 Messages postés lundi 7 décembre 2009Date d'inscriptionContributeurStatut 11 avril 2018 Dernière intervention
- 26 août 2011 à 18:54
Salut a tous

Je fait un application en VB.NET qui affiche / edit, les info d'une BD ACCESS.

l'affichage dans la datagridview marche bien, mais quand je change une valeur, mon code n'update pas ma BD.

Pouvez vous m'aider SVP.




Public Class MAIN
    Public con As New OleDb.OleDbConnection
    Public dbProvider As String
    Public dbSource As String
    Public ds As New DataSet
    Public da As OleDb.OleDbDataAdapter
    Public SQL As String

   Private Sub MAIN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        connection()


        SQL = "SELECT * FROM bom "

        da = New OleDb.OleDbDataAdapter(SQL, con)
        ds.Clear()
        ds.Reset()
        da.Fill(ds, "data")

        DataGridView1.DataSource = ds.Tables(0)

end sub


Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

        Dim cb As New OleDb.OleDbCommandBuilder(da)
        da.Update(ds, "DATA")

    End Sub

Afficher la suite 

Votre réponse

3 réponses

rapidozoo 4 Messages postés mardi 12 décembre 2000Date d'inscription 26 août 2011 Dernière intervention - 26 août 2011 à 05:32
0
Merci
En fessant plus de test, je viens de constater, que le update ne ce fait pas a tous les coups

merci de votre aide

voci mon code complet



Imports System.Data
Imports System.Data.OleDb
Imports ADODB




Public Class MAIN
Public con As New OleDb.OleDbConnection
Public dbProvider As String
Public dbSource As String
Public ds As New DataSet
Public da As OleDb.OleDbDataAdapter
Public SQL As String
Public NBS_ACHAT_N As Integer
Public NBS_ACHAT_C As Integer
Public NBS_ACHAT_O As Integer
Public NBS_LASER_N As Integer
Public NBS_LASER_C As Integer
Public NBS_LASER_O As Integer
Public NBS_PLIAGE_N As Integer
Public NBS_PLIAGE_C As Integer
Public NBS_PLIAGE_O As Integer
Public NBS_USINAGE_N As Integer
Public NBS_USINAGE_C As Integer
Public NBS_USINAGE_O As Integer
Public NBS_SOUDAGE_N As Integer
Public NBS_SOUDAGE_C As Integer
Public NBS_SOUDAGE_O As Integer


Sub FiltreProjet_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiltreProjet.SelectedIndexChanged


FiltreSection.Text = ""
FiltrePlan.Text = ""
REMPLIR_FILTRE(FiltreProjet.Text, FiltreSection.Text, FiltrePlan.Text)

sql = "SELECT * FROM bom WHERE LIGNE_BOM LIKE '" & FiltreProjet.Text & "-%'"
da = New OleDb.OleDbDataAdapter(SQL, con)
ds.Clear()
ds.Reset()
da.Fill(ds, "data")


STATISTIQUE()

Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

countr = ds.Tables(0).Rows.Count
countc = ds.Tables(0).Columns.Count
countt = ds.Tables.Count


DataGridView1.DataSource = ds.Tables(0)
affiche()

End Sub




Sub RESET_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RESET.Click

SQL = "SELECT * FROM bom "

da = New OleDb.OleDbDataAdapter(sql, con)
ds.Clear()
ds.Reset()
da.Fill(ds, "data")

STATISTIQUE()

Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

countr = ds.Tables(0).Rows.Count
countc = ds.Tables(0).Columns.Count
countt = ds.Tables.Count
DataGridView1.DataSource = ds.Tables(0)
' affiche()

FiltreProjet.SelectedItem = -1
FiltreProjet.SelectedItem = -1
FiltreSection.SelectedItem = -1
FiltreSection.SelectedItem = -1
FiltrePlan.SelectedItem = -1
FiltrePlan.SelectedItem = -1

FiltreProjet.Items.Clear()
FiltreSection.Items.Clear()
FiltrePlan.Items.Clear()

FiltreProjet.Text = ""
FiltreSection.Text = ""
FiltrePlan.Text = ""

REMPLIR_FILTRE(FiltreProjet.Text, FiltreSection.Text, FiltrePlan.Text)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

con.Close()

Me.Close()

End Sub
Sub REMPLIR_FILTRE(ByVal PROJET As String, ByVal SECTION As String, ByVal PLAN As String)



Dim daCB As OleDb.OleDbDataAdapter
Dim sqlCB As String
Dim dsCB As New DataSet



Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

Dim a As String
Dim i As Integer



If PROJET "" And SECTION "" Then
FiltreProjet.Items.Clear()
FiltreSection.Items.Clear()
FiltrePlan.Items.Clear()
FiltreProjet.Text = ""
FiltreSection.Text = ""
FiltrePlan.Text = ""

sqlCB = "SELECT Left([dessin],4) FROM DESSIN GROUP BY Left([dessin],4) "
daCB = New OleDb.OleDbDataAdapter(sqlCB, con)
daCB.Fill(dsCB, "data")


countr = dsCB.Tables(0).Rows.Count
countc = dsCB.Tables(0).Columns.Count
countt = dsCB.Tables.Count

If countr > 0 Then
For i = 0 To countr - 1
' a = dsCB.Tables(0).Rows(i).Item(0)
FiltreProjet.Items.Add(dsCB.Tables(0).Rows(i).Item(0))
Next
End If

End If

If PROJET "" And SECTION = "" Then
FiltreSection.Items.Clear()
FiltrePlan.Items.Clear()
FiltreSection.Text = ""
FiltrePlan.Text = ""

sqlCB = "SELECT Mid([dessin],6,3) FROM DESSIN WHERE DESSIN LIKE '" & PROJET & "-%'"

daCB = New OleDb.OleDbDataAdapter(sqlCB, con)
daCB.Fill(dsCB, "data")

countr = dsCB.Tables(0).Rows.Count
countc = dsCB.Tables(0).Columns.Count
countt = dsCB.Tables.Count

If countr > 0 Then
For i = 0 To countr - 1
a = dsCB.Tables(0).Rows(i).Item(0)
FiltreSection.Items.Add(dsCB.Tables(0).Rows(i).Item(0))
Next
End If
End If



If PROJET "" And SECTION "" Then
FiltrePlan.Items.Clear()
FiltrePlan.Text = ""

sqlCB = "SELECT Mid([dessin],10,2) FROM DESSIN WHERE DESSIN LIKE '" & PROJET & "-" & SECTION & "-%'"

daCB = New OleDb.OleDbDataAdapter(sqlCB, con)
daCB.Fill(dsCB, "data")

countr = dsCB.Tables(0).Rows.Count
countc = dsCB.Tables(0).Columns.Count
countt = dsCB.Tables.Count

If countr > 0 Then
For i = 0 To countr - 1
a = dsCB.Tables(0).Rows(i).Item(0)
FiltrePlan.Items.Add(dsCB.Tables(0).Rows(i).Item(0))
Next
End If
End If












End Sub
Sub connection()



Dim ip As String
ip = My.Computer.Name



dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
If ip = "COTE-41F9E2EDFD" Then
dbSource "Data Source U:\pmg\db\pmg dessin.mdb"
Else
dbSource "Data Source y:\daniel cote\db\pmg dessin.mdb"
End If
con.ConnectionString = dbProvider & dbSource
con.Open()



End Sub

Sub FiltreSection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiltreSection.SelectedIndexChanged


FiltrePlan.Text = ""

REMPLIR_FILTRE(FiltreProjet.Text, FiltreSection.Text, FiltrePlan.Text)

Dim sql As String
Dim ds As New DataSet
sql = "SELECT * FROM bom WHERE LIGNE_BOM LIKE '" & FiltreProjet.Text & "-" & FiltreSection.Text & "-%'"



da = New OleDb.OleDbDataAdapter(sql, con)
ds.Clear()
ds.Reset()
da.Fill(ds, "data")

STATISTIQUE()

Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

countr = ds.Tables(0).Rows.Count
countc = ds.Tables(0).Columns.Count
countt = ds.Tables.Count

DataGridView1.DataSource = ds.Tables(0)
affiche()



End Sub

Sub FiltrePlan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiltrePlan.SelectedIndexChanged

Dim sql As String
Dim ds As New DataSet
sql = "SELECT * FROM bom WHERE LIGNE_BOM LIKE '" & FiltreProjet.Text & "-" & FiltreSection.Text & "-" & FiltrePlan.Text & "-%'"



da = New OleDb.OleDbDataAdapter(sql, con)
ds.Clear()
ds.Reset()
da.Fill(ds, "data")


STATISTIQUE()


Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

countr = ds.Tables(0).Rows.Count
countc = ds.Tables(0).Columns.Count
countt = ds.Tables.Count

DataGridView1.DataSource = ds.Tables(0)
affiche()

End Sub




Private Sub MAIN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connection()


SQL = "SELECT * FROM bom "

da = New OleDb.OleDbDataAdapter(SQL, con)
ds.Clear()
ds.Reset()
da.Fill(ds, "data")

STATISTIQUE()

Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

countr = ds.Tables(0).Rows.Count
countc = ds.Tables(0).Columns.Count
countt = ds.Tables.Count
DataGridView1.DataSource = ds.Tables(0)

'(affiche())





FiltreProjet.SelectedItem = -1
FiltreProjet.SelectedItem = -1
FiltreSection.SelectedItem = -1
FiltreSection.SelectedItem = -1
FiltrePlan.SelectedItem = -1
FiltrePlan.SelectedItem = -1

FiltreProjet.Items.Clear()
FiltreSection.Items.Clear()
FiltrePlan.Items.Clear()

FiltreProjet.Text = ""
FiltreSection.Text = ""
FiltrePlan.Text = ""

REMPLIR_FILTRE(FiltreProjet.Text, FiltreSection.Text, FiltrePlan.Text)




End Sub


Sub STATISTIQUE()





Dim dstemp As New DataSet
Dim sqltemp As String
Dim datemp As OleDb.OleDbDataAdapter

Dim countr As Integer
Dim countc As Integer
Dim countt As Integer

If SQL "SELECT * FROM bom " Then SQL "select * from bom where ligne_bom '0'"
sqltemp SQL & " and ACHAT 'N'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_ACHAT_N = dstemp.Tables(0).Rows.Count
TextBox1.Text = NBS_ACHAT_N
sqltemp SQL & " and ACHAT 'C'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_ACHAT_C = dstemp.Tables(0).Rows.Count
TextBox2.Text = NBS_ACHAT_C
sqltemp SQL & " and ACHAT 'O'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_ACHAT_O = dstemp.Tables(0).Rows.Count
TextBox3.Text = NBS_ACHAT_O

sqltemp SQL & " and LASER 'N'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_LASER_N = dstemp.Tables(0).Rows.Count
TextBox4.Text = NBS_LASER_N
sqltemp SQL & " and LASER 'C'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_LASER_C = dstemp.Tables(0).Rows.Count
TextBox5.Text = NBS_LASER_C
sqltemp SQL & " and LASER 'O'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_LASER_O = dstemp.Tables(0).Rows.Count
TextBox6.Text = NBS_LASER_O

sqltemp SQL & " and PLIAGE 'N'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_PLIAGE_N = dstemp.Tables(0).Rows.Count
TextBox7.Text = NBS_PLIAGE_N
sqltemp SQL & " and PLIAGE 'C'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_PLIAGE_C = dstemp.Tables(0).Rows.Count
TextBox8.Text = NBS_PLIAGE_C
sqltemp SQL & " and PLIAGE 'O'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_PLIAGE_O = dstemp.Tables(0).Rows.Count
TextBox9.Text = NBS_PLIAGE_O


sqltemp SQL & " and USINAGE 'N'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_USINAGE_N = dstemp.Tables(0).Rows.Count
TextBox10.Text = NBS_USINAGE_N
sqltemp SQL & " and USINAGE 'C'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_USINAGE_C = dstemp.Tables(0).Rows.Count
TextBox11.Text = NBS_USINAGE_C
sqltemp SQL & " and USINAGE 'O'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_USINAGE_O = dstemp.Tables(0).Rows.Count
TextBox12.Text = NBS_USINAGE_O

sqltemp SQL & " and SOUDAGE 'N'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_SOUDAGE_N = dstemp.Tables(0).Rows.Count
TextBox13.Text = NBS_SOUDAGE_N
sqltemp SQL & " and SOUDAGE 'C'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_SOUDAGE_C = dstemp.Tables(0).Rows.Count
TextBox14.Text = NBS_SOUDAGE_C
sqltemp SQL & " and SOUDAGE 'O'"
datemp = New OleDb.OleDbDataAdapter(sqltemp, con)
dstemp.Clear()
dstemp.Reset()
datemp.Fill(dstemp, "temp")
NBS_SOUDAGE_O = dstemp.Tables(0).Rows.Count
TextBox15.Text = NBS_SOUDAGE_O
End Sub

Sub affiche()
' Exit Sub


Dim i As Integer
Dim j As Integer

For i = 0 To 15
DataGridView1.Columns(i).ReadOnly = True
Next





For i = 0 To DataGridView1.RowCount - 1
For j = 17 To DataGridView1.ColumnCount - 1
If Not IsDBNull(DataGridView1.Item(j, i).Value) Then
If DataGridView1.Item(j, i).Value "N" Then DataGridView1.Item(j, i).Style.BackColor Color.Red
If DataGridView1.Item(j, i).Value "C" Then DataGridView1.Item(j, i).Style.BackColor Color.Yellow
If DataGridView1.Item(j, i).Value "O" Then DataGridView1.Item(j, i).Style.BackColor Color.Green
End If

Next

Next


For i = 3 To 15
DataGridView1.Columns(i).Visible = False

Next

For i = 16 To DataGridView1.ColumnCount - 1
DataGridView1.Columns(i).Width = 70
DataGridView1.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter

Next


End Sub



Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

Dim cb As New OleDb.OleDbCommandBuilder(da)
da.Update(ds, "DATA")
da.Update(ds, "DATA")
da.Update(ds, "DATA")

End Sub
End Class


Commenter la réponse de rapidozoo
NHenry 14209 Messages postés vendredi 14 mars 2003Date d'inscription 23 juin 2018 Dernière intervention - 26 août 2011 à 12:47
0
Merci
Bonjour,

A la place de mettre que la balise code, utilises aussi le langage, la coloration syntaxique rendre tes messages plus digestes.

Presque pas de commentaire, donc il faut tenter des retrouver à quoi servent les lignes de code (sans coloration syntaxique en plus), je n'ai pas le temps de chercher à tout comprendre, avec quelques commentaires, et la coloration syntaxique, tu aura plus de réponses, je pense.

---------------------------------------------------------------------
[list=ordered][*]Pour poser correctement une question et optimiser vos chances d'obtenir des réponses, pensez à lire le règlement CS et aussi ce lien[*]Quand vous postez un code, merci d'utiliser la coloration syntaxique (3ième icône en partant de la droite : )
[*]Si votre problème est résolu (et uniquement si c'est le cas), pensez à mettre "Réponse acceptée" sur le ou les messages qui vous ont aidés./list
---
Mon site
Commenter la réponse de NHenry
ucfoutu 18039 Messages postés lundi 7 décembre 2009Date d'inscriptionContributeurStatut 11 avril 2018 Dernière intervention - 26 août 2011 à 18:54
0
Merci
Bonjour,

Désolé, mais je ne peux résister (surtout un vendredi) :
En fessant plus de test, je viens de constater, que le update ne ce fait pas a tous les coups

J'espère que tu n'en donnes pas trop.
Pas plus de 5 coups par fessée, hein .. et pas trop fort, s'il te plait



____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne intallée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
Commenter la réponse de ucfoutu

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.