Update Access Database with DataSet










1















I am writing because I have a problem with updating my access database with the dataset. i am getting no errors but the database doesn't seem to update.
Here is my code:



public partial class Form1 : Form{
private DataSet ds = new DataSet();
string dbconnection = "Provider=Microsoft.JET.OLEDB.4.0;" + @"data source =../../database/Log1.mdb";
string dbcommand = "SELECT * FROM Log";

private void addRow(int action)

string actionCase = "Uknown action";
switch (action)

case 1:
actionCase = "Nothing";
break;
case 2:
actionCase = "Is";
break;
case 3:
actionCase = "Working";
break;
case 4:
actionCase = "what";
break;

DataRow row = ds.Tables["Log"].NewRow();
row["action"] = actionCase;
row["actionDateAndTime"] = DateTime.Now.ToString();
ds.Tables["Log"].Rows.Add(row);
ds.AcceptChanges();


private void button_Click(object sender, EventArgs e)

addRow(1);
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(dbcommand, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(ds, "Log");



The database has 3 columns, ID being a primary key, action and actionDateAndTime, both set to Short Text.










share|improve this question

















  • 1





    "the database doesn't seem to update" - doesn't seems to update or is not updated? Is database working elsewhere?

    – Sinatr
    Nov 14 '18 at 15:04






  • 1





    Maybe the output database is copied from project folder to bin every time solution is started. How you check that no rows are in db?

    – Grzesiek Danowski
    Nov 14 '18 at 15:05






  • 1





    .. and it still empty no matter what you add? How do you check? By restarting the software or by observing file with something else? Typical error is to set "copy to output folder" for mdb-file included into project.

    – Sinatr
    Nov 14 '18 at 15:09






  • 1





    Accodring to this answer you are missing at least insert command, because you are not updating existing field, but adding a new one.

    – Sinatr
    Nov 14 '18 at 15:25






  • 1





    AcceptChanges() doesnt do what you think it does. It clears all the change flags so that there is nothing to update. Also, if you just have one DataTable, a DataSet is overkill and if you hold one to the DataAdapter you dont have to GetUpDateCommand or create a connection every time - a DataAdapter can be very powerful

    – None of the Above
    Nov 14 '18 at 15:26















1















I am writing because I have a problem with updating my access database with the dataset. i am getting no errors but the database doesn't seem to update.
Here is my code:



public partial class Form1 : Form{
private DataSet ds = new DataSet();
string dbconnection = "Provider=Microsoft.JET.OLEDB.4.0;" + @"data source =../../database/Log1.mdb";
string dbcommand = "SELECT * FROM Log";

private void addRow(int action)

string actionCase = "Uknown action";
switch (action)

case 1:
actionCase = "Nothing";
break;
case 2:
actionCase = "Is";
break;
case 3:
actionCase = "Working";
break;
case 4:
actionCase = "what";
break;

DataRow row = ds.Tables["Log"].NewRow();
row["action"] = actionCase;
row["actionDateAndTime"] = DateTime.Now.ToString();
ds.Tables["Log"].Rows.Add(row);
ds.AcceptChanges();


private void button_Click(object sender, EventArgs e)

addRow(1);
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(dbcommand, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(ds, "Log");



The database has 3 columns, ID being a primary key, action and actionDateAndTime, both set to Short Text.










share|improve this question

















  • 1





    "the database doesn't seem to update" - doesn't seems to update or is not updated? Is database working elsewhere?

    – Sinatr
    Nov 14 '18 at 15:04






  • 1





    Maybe the output database is copied from project folder to bin every time solution is started. How you check that no rows are in db?

    – Grzesiek Danowski
    Nov 14 '18 at 15:05






  • 1





    .. and it still empty no matter what you add? How do you check? By restarting the software or by observing file with something else? Typical error is to set "copy to output folder" for mdb-file included into project.

    – Sinatr
    Nov 14 '18 at 15:09






  • 1





    Accodring to this answer you are missing at least insert command, because you are not updating existing field, but adding a new one.

    – Sinatr
    Nov 14 '18 at 15:25






  • 1





    AcceptChanges() doesnt do what you think it does. It clears all the change flags so that there is nothing to update. Also, if you just have one DataTable, a DataSet is overkill and if you hold one to the DataAdapter you dont have to GetUpDateCommand or create a connection every time - a DataAdapter can be very powerful

    – None of the Above
    Nov 14 '18 at 15:26













1












1








1








I am writing because I have a problem with updating my access database with the dataset. i am getting no errors but the database doesn't seem to update.
Here is my code:



public partial class Form1 : Form{
private DataSet ds = new DataSet();
string dbconnection = "Provider=Microsoft.JET.OLEDB.4.0;" + @"data source =../../database/Log1.mdb";
string dbcommand = "SELECT * FROM Log";

private void addRow(int action)

string actionCase = "Uknown action";
switch (action)

case 1:
actionCase = "Nothing";
break;
case 2:
actionCase = "Is";
break;
case 3:
actionCase = "Working";
break;
case 4:
actionCase = "what";
break;

DataRow row = ds.Tables["Log"].NewRow();
row["action"] = actionCase;
row["actionDateAndTime"] = DateTime.Now.ToString();
ds.Tables["Log"].Rows.Add(row);
ds.AcceptChanges();


private void button_Click(object sender, EventArgs e)

addRow(1);
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(dbcommand, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(ds, "Log");



The database has 3 columns, ID being a primary key, action and actionDateAndTime, both set to Short Text.










share|improve this question














I am writing because I have a problem with updating my access database with the dataset. i am getting no errors but the database doesn't seem to update.
Here is my code:



public partial class Form1 : Form{
private DataSet ds = new DataSet();
string dbconnection = "Provider=Microsoft.JET.OLEDB.4.0;" + @"data source =../../database/Log1.mdb";
string dbcommand = "SELECT * FROM Log";

private void addRow(int action)

string actionCase = "Uknown action";
switch (action)

case 1:
actionCase = "Nothing";
break;
case 2:
actionCase = "Is";
break;
case 3:
actionCase = "Working";
break;
case 4:
actionCase = "what";
break;

DataRow row = ds.Tables["Log"].NewRow();
row["action"] = actionCase;
row["actionDateAndTime"] = DateTime.Now.ToString();
ds.Tables["Log"].Rows.Add(row);
ds.AcceptChanges();


private void button_Click(object sender, EventArgs e)

addRow(1);
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(dbcommand, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(ds, "Log");



The database has 3 columns, ID being a primary key, action and actionDateAndTime, both set to Short Text.







c#






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 14:59









PpottoPpotto

184




184







  • 1





    "the database doesn't seem to update" - doesn't seems to update or is not updated? Is database working elsewhere?

    – Sinatr
    Nov 14 '18 at 15:04






  • 1





    Maybe the output database is copied from project folder to bin every time solution is started. How you check that no rows are in db?

    – Grzesiek Danowski
    Nov 14 '18 at 15:05






  • 1





    .. and it still empty no matter what you add? How do you check? By restarting the software or by observing file with something else? Typical error is to set "copy to output folder" for mdb-file included into project.

    – Sinatr
    Nov 14 '18 at 15:09






  • 1





    Accodring to this answer you are missing at least insert command, because you are not updating existing field, but adding a new one.

    – Sinatr
    Nov 14 '18 at 15:25






  • 1





    AcceptChanges() doesnt do what you think it does. It clears all the change flags so that there is nothing to update. Also, if you just have one DataTable, a DataSet is overkill and if you hold one to the DataAdapter you dont have to GetUpDateCommand or create a connection every time - a DataAdapter can be very powerful

    – None of the Above
    Nov 14 '18 at 15:26












  • 1





    "the database doesn't seem to update" - doesn't seems to update or is not updated? Is database working elsewhere?

    – Sinatr
    Nov 14 '18 at 15:04






  • 1





    Maybe the output database is copied from project folder to bin every time solution is started. How you check that no rows are in db?

    – Grzesiek Danowski
    Nov 14 '18 at 15:05






  • 1





    .. and it still empty no matter what you add? How do you check? By restarting the software or by observing file with something else? Typical error is to set "copy to output folder" for mdb-file included into project.

    – Sinatr
    Nov 14 '18 at 15:09






  • 1





    Accodring to this answer you are missing at least insert command, because you are not updating existing field, but adding a new one.

    – Sinatr
    Nov 14 '18 at 15:25






  • 1





    AcceptChanges() doesnt do what you think it does. It clears all the change flags so that there is nothing to update. Also, if you just have one DataTable, a DataSet is overkill and if you hold one to the DataAdapter you dont have to GetUpDateCommand or create a connection every time - a DataAdapter can be very powerful

    – None of the Above
    Nov 14 '18 at 15:26







1




1





"the database doesn't seem to update" - doesn't seems to update or is not updated? Is database working elsewhere?

– Sinatr
Nov 14 '18 at 15:04





"the database doesn't seem to update" - doesn't seems to update or is not updated? Is database working elsewhere?

– Sinatr
Nov 14 '18 at 15:04




1




1





Maybe the output database is copied from project folder to bin every time solution is started. How you check that no rows are in db?

– Grzesiek Danowski
Nov 14 '18 at 15:05





Maybe the output database is copied from project folder to bin every time solution is started. How you check that no rows are in db?

– Grzesiek Danowski
Nov 14 '18 at 15:05




1




1





.. and it still empty no matter what you add? How do you check? By restarting the software or by observing file with something else? Typical error is to set "copy to output folder" for mdb-file included into project.

– Sinatr
Nov 14 '18 at 15:09





.. and it still empty no matter what you add? How do you check? By restarting the software or by observing file with something else? Typical error is to set "copy to output folder" for mdb-file included into project.

– Sinatr
Nov 14 '18 at 15:09




1




1





Accodring to this answer you are missing at least insert command, because you are not updating existing field, but adding a new one.

– Sinatr
Nov 14 '18 at 15:25





Accodring to this answer you are missing at least insert command, because you are not updating existing field, but adding a new one.

– Sinatr
Nov 14 '18 at 15:25




1




1





AcceptChanges() doesnt do what you think it does. It clears all the change flags so that there is nothing to update. Also, if you just have one DataTable, a DataSet is overkill and if you hold one to the DataAdapter you dont have to GetUpDateCommand or create a connection every time - a DataAdapter can be very powerful

– None of the Above
Nov 14 '18 at 15:26





AcceptChanges() doesnt do what you think it does. It clears all the change flags so that there is nothing to update. Also, if you just have one DataTable, a DataSet is overkill and if you hold one to the DataAdapter you dont have to GetUpDateCommand or create a connection every time - a DataAdapter can be very powerful

– None of the Above
Nov 14 '18 at 15:26












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303090%2fupdate-access-database-with-dataset%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303090%2fupdate-access-database-with-dataset%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto