Click here to Skip to main content
Sign Up to vote bad
good
See more: C#databasedataset
Hi,
 
I have a problem updating a dataset / database.
There is a table "TblPerson" with the name and the "Age". The form consids a datagridview of "TblPerson", a combobox for "IDPerson", a textbox for "Age" and buttons for loading the database, updating the dataset and saving to the Database.
 
Loading the data to the datagridview and the comboboxes works fine. When I do changes in the "Age" textfield and press the update button, the datagridview shows the changes.
But when I want so save this to the database, there is no data registered to be updated.
But after doing the changes direkt in the datagridview, saving to the DB works fine.
 
I wonder about this, because the dataset always shows the correct updated data. Maybe the comboboxes and textfields do not registrate the change in the dataset.
 
Can somebody help me?
 
Thanks and best regards!
 

 
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
 
namespace Test3_Join
{
    public partial class Form1 : Form
    {
        private DataSet ds = new DataSet();
        private DataViewManager dsView;
        OleDbDataAdapter AdapterTblPerson;
        OleDbConnection con;
        OleDbCommand cmd = new OleDbCommand();
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click_1(object sender, EventArgs e)
        {
            string connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\...\\Database.accdb;Persist Security Info=False;";
            con = new OleDbConnection(connetionString);
            ds.Locale = System.Globalization.CultureInfo.InvariantCulture;
            cmd.Connection = con;
 
            cmd.CommandText = "SELECT * FROM TblPerson";
            AdapterTblPerson = new OleDbDataAdapter(cmd);
            AdapterTblPerson.Fill(ds, "TblPerson");
 
            dsView = ds.DefaultViewManager;
 
            cboIDConnector.DataSource = dsView;
            cboIDConnector.DisplayMember = "TblPerson.IDPerson";
            cboIDConnector.ValueMember = "TblPerson.IDPerson";
 
            tbPinAmount.DataBindings.Add("Text", dsView, "TblPerson.Age");
        }
 
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            OleDbCommandBuilder cb = new OleDbCommandBuilder(AdapterTblPerson);
            int count = AdapterTblPerson.Update(ds.Tables["TblPerson"]);
            textBox1.Text = count.ToString();
            textBox1.AppendText("\r" + cb.GetUpdateCommand().ToString());
        }
 
        private void btnLoadTable_Click(object sender, EventArgs e)
        {
            dataGridView1.Refresh();
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "TblPerson";
        }
 
    }
}
Posted 12 Jul '12 - 2:51

Comments
biswarup88 - 21 Jul '12 - 5:01
where's your update query?

1 solution

I dont't wont to update the database at this point. I just need it in the dataset at first.
  Permalink  
Comments
gladiatron - 23 Aug '12 - 10:15
you don't put your comments in the solution box! Put them in the comments box by clicking "Reply" to the comments posted right below your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 355
1 Sergey Alexandrovich Kryukov 338
2 Arun Vasu 315
3 Maciej Los 208
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,549
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 23 Aug 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid