Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:57:03+00:00 2026-06-03T22:57:03+00:00

I am adding records to my database via a windows form. But when ever

  • 0

I am adding records to my database via a windows form. But when ever I add a new record it doesnt update until I close the app and then start again. Even though I think I am telling it to update (Im obv not!!)

Do I need a new varibale to update the database? Im a little stuck.

EDIT: All code on this..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace MediaManagementSystem
{
public partial class AddMedia : Form
{
    //database var
    OleDbConnection m_cnADONetConnection = new OleDbConnection();
    OleDbDataAdapter m_daDataAdapter;
    OleDbDataAdapter m_cbCommandBuilder;
    DataTable m_dtMedia = new DataTable();
    int m_rowPosition = 0;

    public AddMedia()
    {
        InitializeComponent();
    }

    private void BrowseButton_Click(object sender, EventArgs e)
    {
        //load up file dialog and find media
        if (addFileDialog.ShowDialog() == DialogResult.OK)
        {
            //add media file name to file path text box
            txtFilePath.Text = addFileDialog.FileName;
        }
    }

    private void CancelButton_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void AddButton_Click(object sender, EventArgs e)
    {
        //add the new record to the database
        DataRow drNewRow = m_dtMedia.NewRow();
        drNewRow["FilePath"] = txtFilePath.Text;
        drNewRow["Subject"] = txtSubject.Text;
        drNewRow["Title"] = txtTitle.Text;
        drNewRow["Keywords"] = txtKeywords.Text;
        drNewRow["MediaType"] = AddComboBox.Text;
        m_dtMedia.Rows.Add(drNewRow);

        m_daDataAdapter.Update(m_dtMedia);
        m_rowPosition = m_dtMedia.Rows.Count - 1;
        this.ShowCurrentRecord();
        this.Close();
    }

    private void AddMedia_Load(object sender, EventArgs e)
    {
        //link to the database and conect to database
        m_cnADONetConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Max\Documents\Visual Studio 2010\Projects\MediaManagementSystem\MediaManagementSystem\bin\Debug\MediaDB.mdb";
        m_cnADONetConnection.Open();
        OleDbConnection objConnection = new OleDbConnection(m_cnADONetConnection.ConnectionString);

        m_daDataAdapter = new OleDbDataAdapter("Select * From Media", m_cnADONetConnection);

        OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daDataAdapter);
        m_daDataAdapter.Fill(m_dtMedia);
        m_daDataAdapter.Update(m_dtMedia);
    }

    public void ShowCurrentRecord()
    {
        m_daDataAdapter.Update(m_dtMedia);   

        if (m_dtMedia.Rows.Count == 0)
        {
            txtFilePath.Text = "";
            txtSubject.Text = "";
            txtTitle.Text = "";
            txtKeywords.Text = "";
            AddComboBox.Text = "";
            return;
        }
        txtFilePath.Text = m_dtMedia.Rows[m_rowPosition]["FilePath"].ToString();
        txtSubject.Text = m_dtMedia.Rows[m_rowPosition]["Subject"].ToString();
        txtTitle.Text = m_dtMedia.Rows[m_rowPosition]["Title"].ToString();
        txtKeywords.Text = m_dtMedia.Rows[m_rowPosition]["Keywords"].ToString();
        AddComboBox.Text = m_dtMedia.Rows[m_rowPosition]["MediaType"].ToString();
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:57:05+00:00Added an answer on June 3, 2026 at 10:57 pm

    It would best if you use DataSet and then update the records in it. Finally you need to call AcceptChanges() after the update() command to commit the changes with dataset something as below also reload the data after to enter to get the recent data info:
    dataset.AcceptChanges()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, you are submitting a form, which affects your database (adding records/ deleting them/
i have one php file which process adding of record in Database fro array.
Been succcesfully adding records using Linq2Sql with the linq2sql genereated classes, works great.. But
I have seen various answers around helping explain adding records in one-to-many relationships but
I wish to use the same form for adding and editing records within a
I have a web site with which I am adding records to a database
I'm currently attempting to update existing records within a MySQL database. Prior to the
I am looking for a recipe for adding Drupal node records. I have identified
I am adding a series of records (eg 100) per single transaction. I want
Adding Exceptional Handling is a good practise, but I have a doubt, In our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.