Jelmer Posted March 3, 2006 Posted March 3, 2006 Hello, I've got a form with a datagridview, if i press the mouse button on a record some textfields are filled with the data of that row. You can change the data in the textfields, and press a button to save the changes. The result is that the changes are saved into the MDB database. But my datagridview doesn't wanne show the new data. Only if i restart the whole program. I'll tried dataviewgrid1.refresh(), but that doesnt help me. Both do use another connection to the database. The datagridview is build with the wizzard. The save function is in a class. How can i refresh or close and open the databaseconnection ? The datasource of the dataviewgrid is: productenCategorieBindingSource1 Thnx Jelmer Quote
Puiu Posted March 3, 2006 Posted March 3, 2006 If your data source is a dataset then do something like this: dataset.clear and after that fill the dataset again If you do not use a dataset, then simply reconnect to the mdb file again Quote
Jelmer Posted March 6, 2006 Author Posted March 6, 2006 (edited) If i clear the dataset the dataviewgrid is empty.. so thats okay. (billingdataset11) But now i need to fill it again.. The Datasource of the dataviewgrid is: productenCategorieBindingSource1 The Productencategoriebindingsource1.Datasource = billingDataset11 But how can i fill it again ? :rolleyes: :o If i close the form and open it again (i press a button from the main form) than is the data there but not the updated data.. i need to restart the application for the new data... thats not ok.. Edited March 6, 2006 by Jelmer Quote
*Experts* Nerseus Posted March 6, 2006 *Experts* Posted March 6, 2006 If the controls and grid are bound to the same DataSet then the changes should update immediately. If you use a different dataset, you'll have to manually refresh the grid's dataset after you save to the DB. The two connections shouldn't matter - it comes down to what you're binding to the grid. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Jelmer Posted March 6, 2006 Author Posted March 6, 2006 If the controls and grid are bound to the same DataSet then the changes should update immediately. If you use a different dataset, you'll have to manually refresh the grid's dataset after you save to the DB. The two connections shouldn't matter - it comes down to what you're binding to the grid. -ner I'll add or change some data in a class.. The grid on the form is another datagrid. But if i refresh that datagrid, i'll still get old data.. This is the code how i add data to the mdb database: OleDbConnection Connection = new OleDbConnection(); Connection = dbase(Connection); // Create an OleDb command, OleDbCommand command = new OleDbCommand(); command.Connection = Connection; command.CommandText = "insert into Producten (Naam,Prijs,Opmerkingen,Categorie,BTW) values('" + Naam + "','" + Prijs + "','" + Opmerkingen + "','" + Categorie + "','" + BTW + "') "; //MessageBox.Show("update Bedrijven set Bedrijf = '" + Bedrijf + "', Contactpersoon = '" + Contactpersoon + "', Adres = '" + Adres + "', Postcode = '" + Postcode + "', Plaats = '" + Plaats + "', Tel = '" + Tel + "', Mobiel = '" + Mobiel + "', Fax = '" + Fax + "', Email = '" + Email + "', Website = '"+ Website + "', kvk = '" + KVK + "', BTW = '" + BTW + "', debiteurnr = '" + Debiteurnr + "', opmerkingen = '" + Opmerkingen + "' where id = " + ID); command.ExecuteNonQuery(); After this code is runned, the data is in de database ! But the grid doesnt show that data.. After a restart of the whole program i can see the changed data in the grid. So i need to deconnect the Bindingsources ore something ? But i cant find it.. i build them in a wizzard.. Used to work with Delphi.. there its a pice of cake... connection.false; and connection.treu; and you'll get the recent data. Quote
Administrators PlausiblyDamp Posted March 6, 2006 Administrators Posted March 6, 2006 If you are binding to a DataSet / DataTable then you will need to refresh it's contents after you have updated the DB as the Dataset does not maintain a connection to the DB it cannot automatically update itself. Just use the same dataadapter.Fill you used to populate the datatable originally. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jelmer Posted March 6, 2006 Author Posted March 6, 2006 That code above is used in a class. So i cant use the dataset of the form where i am. First i press a butten, that uses the class, and adds something to the database. After that i will show it on the form. I've got a DataGridView1 that uses as datasource productenCategorieBindingSource1 that uses as datasource billingdataset11. With billingdataset11.clear(); i can clear the list. But how to fill the data ... wich commands.. ???? I've tried to connect.. doesnt work, refresh isnt available, reload not.. etc. I'll use .Net. why is that so difficult.. ist as easy as that.. :( , its easier to build a datagridview by myzelf.. :rolleyes: Quote
Cags Posted March 6, 2006 Posted March 6, 2006 I think your missing the point of what people are suggesting (or maybe I am). If your application works when you open it new, then whatever code you are using to populate the DataGridView in the firstplace can be used to refresh the info. Simply clear all the information then use the same lines of code as your app uses on load to re-populate it. Quote Anybody looking for a graduate programmer (Midlands, England)?
tfowler Posted March 6, 2006 Posted March 6, 2006 (edited) Just use DataGridView1.DataBind(). Or, if needed, rebind everything after you perform the update: With DataGridView1 .DataSource = productenCategorieBindingSource1 .DataMember = "<whatever member table you are bound to, if any>" .DataBind() End With Todd Edited March 6, 2006 by tfowler Quote
Jelmer Posted April 10, 2006 Author Posted April 10, 2006 Sorry for my late reaction.. But i use C#, the code above is okay.. but í cant use dataGridView1.databind()... C# doesnt understand that.. what can i use instead of that? Quote
Administrators PlausiblyDamp Posted April 10, 2006 Administrators Posted April 10, 2006 C# is case sensitive - are you typing it correctly? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jelmer Posted April 10, 2006 Author Posted April 10, 2006 C# is case sensitive - are you typing it correctly? Yups.. the error is: System.Windows.Forms.DataGridView does not contain a definition for 'DataBind' Or do i need to include more things?: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using products; using Ini; using statistieken; Quote
Administrators PlausiblyDamp Posted April 10, 2006 Administrators Posted April 10, 2006 DataGridView is a class - you need to use the correct instance of it (DataGridView1 from the sample above). Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jelmer Posted April 13, 2006 Author Posted April 13, 2006 All of the code works.. exept the last rule: dataGridView1.DataSource = productenCategorieBindingSource1; dataGridView1.DataMember = ""; dataGridView1.DataBind(); And of course dataGridView1 is of the correct syntax. In the design mode its an memboer of: System.Windows.Forms.DataGridView Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.