0

I'm trying to polish up an old program I made a few months ago, its essentially a social networking app. As such I'm trying to "write" a new row into one of my tables in Microsoft Access (2010). Before, that was working fine, it was updating as needed/the button pressed. But now, its not.

When I press "Post" it goes through all the lines in the code without issue/error, however the database is not updated. I can't figure out why its not updating, so any assistance is greatly appreciated;

 private void btnPost_Click(object sender, EventArgs e)
    {
        String postText = txtPost.Text;

        String followingIDStr = cboxFollowing.ValueMember.ToString();
        int followingID = Convert.ToInt32(followingIDStr);

        con = new OleDbConnection(connectionString);
        DataSet ds = new DataSet();
        DataRow dRow;
        String sql = "SELECT * FROM Post;";
        OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
        con.Open();
        OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
        DataTable dataTable = new DataTable();
        da.Fill(ds, "Post");

        dRow = ds.Tables["Post"].NewRow();

        dRow[1] = memberID;
        dRow[2] = followingID;
        dRow[3] = "Text";
        dRow[4] = postText;
        dRow[5] = DateTime.Today.Date.ToString();
        dRow[6] = DateTime.Now.ToString("HH:mm");
        dRow[7] = DateTime.Now.ToString("dd/MM/yy HH:mm:ss");

        ds.Tables["Post"].Rows.Add(dRow);
        cb.DataAdapter.Update(ds.Tables["Post"]);

        frmNewsFeed newsFeed = new frmNewsFeed();
        newsFeed.memberID = memberID;
        this.Close();
        newsFeed.Show();
    }
NeoKuro
  • 457
  • 1
  • 5
  • 21
  • Do you have in your project files the database file? If yes check what value is assigned to the property _Copy to output directory_. Then see [this answer](http://stackoverflow.com/questions/17147249/why-saving-changes-to-a-database-fails/17147460#17147460) – Steve Nov 30 '14 at 22:28
  • Yes I do. Where can I find that property? – NeoKuro Nov 30 '14 at 23:37
  • Properties window of the file... – Mikko Viitala Nov 30 '14 at 23:49
  • Right click on the file, select properties. The Properties Windows should appear – Steve Nov 30 '14 at 23:56
  • Ah right, I misread, I had to add the DB file to my projects files, changed it to Do not copy, and it still hasn't worked :/ EDIT: nvm, its saving, I'm just having trouble sorting the Data correctly. If anyone knows a way to ORDER dates/times from most recent, that'd be greatly appreciated :) – NeoKuro Dec 01 '14 at 00:00
  • Nvm, its working now (I forgot the DESC thing at the end) thanks a lot for your help @MikkoViitala and Steve – NeoKuro Dec 01 '14 at 00:09

0 Answers0