Update du dataset

jcnormandin Messages postés 5 Date d'inscription lundi 5 mars 2007 Statut Membre Dernière intervention 5 février 2009 - 14 août 2008 à 17:31
Miltiades Messages postés 233 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 25 octobre 2010 - 14 août 2008 à 18:17
Bonjour, je suis débutant en C# et j'ai un problème avec l'update d'un dataset avec System.Data.SqlClient.

Je suis capable de remplir mon dataset avec le fill. Mais si je modifie mon dataset, je ne suis pas capable de mettre a jour la bd avec le update.

            SqlConnection cn = new SqlConnection();
            DataSet CustomersDataSet = new DataSet();
            SqlDataAdapter da;
            SqlCommandBuilder cmdBuilder;

            //Set the connection string of the SqlConnection object to connect
            //to the SQL Server database in which you created the sample
            //table.
            cn.ConnectionString = "Data Source=localhost;integrated security=SSPI;Initial Catalog=CLASSEURDB";

            cn.Open();

            //Initialize the SqlDataAdapter object by specifying a Select command
            //that retrieves data from the sample table.
            da = new SqlDataAdapter("select Name, NomThick, MinThick, MaxThick from list_Thickness order by ID", cn);

            //Initialize the SqlCommandBuilder object to automatically generate and initialize
            //the UpdateCommand, InsertCommand, and DeleteCommand properties of the SqlDataAdapter.
            cmdBuilder = new SqlCommandBuilder(da);
           

            //Populate the DataSet by running the Fill method of the SqlDataAdapter.
            da.Fill(CustomersDataSet);

            CustomersDataSet.Tables[0].Rows[0]["MaxThick"] = 1.234;
         

            //Modify the value of the CustName field.
            //CustomersDataSet.Tables["Customers"].Rows[0]["CustName"] = "Jack";

            //Post the data modification to the database.
            da.Update(CustomersDataSet);

            //Close the database connection.
            cn.Close();

Merci de votre aide!!

2 réponses

jcnormandin Messages postés 5 Date d'inscription lundi 5 mars 2007 Statut Membre Dernière intervention 5 février 2009
14 août 2008 à 17:55
J'oubliais.

Quand je fais le .update j'ai l'erreur : Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

c'est cette partie que je ne comprends pas.

merci!
0
Miltiades Messages postés 233 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 25 octobre 2010
14 août 2008 à 18:17
c'est pourtant simple, il te dit qu'il est incapable de générer une requête d'update en automatique,
sans doute, parce qu'il n'arrive pas a trouver de clé dans les valeurs retournées,

ca signifie en clair, que c'est a toi de générer la requête d'update.

Nul ne devient grand par la guerre...
0
Rejoignez-nous