Pb update base mySql via un datagrid

abdoulax Messages postés 875 Date d'inscription samedi 17 mai 2003 Statut Membre Dernière intervention 22 juin 2012 - 10 janv. 2006 à 14:26
abdoulax Messages postés 875 Date d'inscription samedi 17 mai 2003 Statut Membre Dernière intervention 22 juin 2012 - 10 janv. 2006 à 14:41
Bonjour je voudrai ma base sql après avoir remplie mon datagrid. Mais je sais pas trop comment m'y prendre. Voici le code :



Imports MySql.DATA.MySqlClient



Public Class clients

Inherits System.Windows.Forms.Form



Dim myData As New DataSet

Dim myAdapter As New MySqlDataAdapter

Dim conn As New MySqlConnection

Dim cmd As New MySqlCommand

Dim myRead As MySqlDataReader

Dim myTable As DataTable



(...) " Code généré par le Concepteur Windows Form "



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



conn.ConnectionString = "server=127.0.0.1;" _

& "uid=root;" _

& "pwd=;" _

& "database=alex"



Try

conn.Open()

cmd.CommandText = "select * from clients"

cmd.Connection = conn



myAdapter.SelectCommand = cmd

myAdapter.Fill(myData)



myTable = myData.Tables(0)

Me.DataGrid1.DataSource = myTable



Catch ex As Exception


MessageBox.Show(ex.Message, "Remplire le datagrid",
MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub



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

Try

myAdapter.Update(myData)

Catch ex As Exception


MessageBox.Show(ex.Message, "Update la bdd", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub

End Class


Have Fun ...

1 réponse

abdoulax Messages postés 875 Date d'inscription samedi 17 mai 2003 Statut Membre Dernière intervention 22 juin 2012 1
10 janv. 2006 à 14:41
Il suffit que je pose la question pour trouver la solution :



myBuilder = New MySqlCommandBuilder(myAdapter)

myAdapter.Update(myData)



Il manquer le CommandBuilder...

Have Fun ...
0
Rejoignez-nous