|
-
Nov 8th, 2007, 10:40 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0] Access Database not Writing
Hi
I'm using the following code, and it adds the row.. in the application. However, it's not actually being saved to the database, even after 3 different AcceptChanges() calls, I will only do this once I was just clutching at straws as to why it wasn't saving.
Here's the code.
Code:
string databaseSource = "responses.mdb";
string databaseCS = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + databaseSource + "";
try
{
OleDbDataAdapter dbAdapter = new OleDbDataAdapter("SELECT * FROM responses", databaseCS);
DataSet responsesTable = new DataSet("responses");
dbAdapter.Fill(responsesTable, "responses");
Console.WriteLine(responsesTable.Tables["responses"].Rows[0]["first_name"]);
DataRow newRecord = responsesTable.Tables["responses"].NewRow();
newRecord["first_name"] = "first name";
newRecord["surname"] = "surname";
newRecord["special"] = "special";
newRecord["telephone"] = "telephone";
newRecord["email"] = "email";
newRecord["company_name"] = "company";
newRecord["title"] = "title";
responsesTable.Tables["responses"].Rows.Add(newRecord);
responsesTable.Tables["responses"].AcceptChanges();
responsesTable.AcceptChanges();
dbAdapter.Update(responsesTable, "responses");
Console.WriteLine(responsesTable.Tables["responses"].Rows[1]["first_name"]);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.ReadLine();
}
Any help as to why it might not be saving would be greatly appreciated.
The access database is very simple. Namely 1 table named responses with the following:
response_id - AutoNumber (Unique)
first_name - Text
surname - Text
special - Text
company_name - Text
title - Text
email - Text
telephone - Text
I'm sure whatever it is that's wrong is pretty simple, but I just can't pin it down!!
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|