Access A Problem?

  • Thread starter Thread starter Curt Emich
  • Start date Start date
C

Curt Emich

I've tried every possible combination of commands to insert a new record
into an Access table, and it just won't happen. Does anyone know if Access
has problems working with .NET?

Check out this link:

http://www.dotnetextreme.com/code/BasicAdo.asp

This is the simplest code sample I've seen anywhere (book or Internet) to
demonstrate how to insert a new record into an Access table (why finding
such an example was like pulling a rhino's teeth is another issue). I
copied the code almost verbatim (mine was VB instead of C#). No dice.

I've made sure my security settings in the folder containing the Access
database are not "read only", etc. Any other ideas, or is ADO.NET a red
herring? I've noticed that a good many other experienced developers are
having difficulty pulling off something this absurdly simple.
 
I use an Access mdb for logging in a .Net app.
It works fine.

The only issue I had was that named parameters don't "work".
If use parameters then the sequence you create them is what counts.
So the first param created must go in the first slot, the 2nd in the 2nd,
etc.
 
Hi Curt:

Access absolutely does work, but if you scroll down a bit, you'll see how
picky it is by virtue of the number of people that post exasperated messages
about it.

There's too many things it could be to just take a guess at, but like John
mentions, either posting a program or at least, so of the code (the command
in question and the call to update).

Also, like always, have you verified HasChanges before calling update? If
not, then calling update all year isn't going to submit the update.

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com
 
Curt,
See my reply to your earlier message 'Trying to Write a New Record'.
I have a billing system that is currently using Access and it works
well. It is in transition to MSDE for the next release though as Access
just doesn't have the performance to work with some of our big contracts.

Ron Allen
 
Bill,

Thanks for getting back to me. Yeah, I'm calling "HasChanges() and it
comes back as true...that's what's really confusing.

Anyway, here's my code:


Thanks for getting back to me. Here's my code below.


thisDataAdapter.InsertCommand = New
OleDb.OleDbCommand("INSERT INTO Sessions (Notes) VALUES(?) ",
OleDbConnection1)

thisDataAdapter.InsertCommand.Parameters.Add("Notes",
OleDbType.VarChar, 15, "Notes")

Dim thisDataset As DataSet = New DataSet()
thisDataAdapter.Fill(thisDataset, "Sessions")

Dim thisTable As New DataTable()

thisTable = thisDataset.Tables("Sessions")

Dim cRow As DataRow = thisDataset.Tables(0).NewRow()
cRow("Notes") = "Yadda"
thisDataset.Tables(0).Rows.Add(cRow)
thisDataAdapter.Update(thisDataset, "Sessions")
 
I'm sending in one paramete and leaving the rest blank. I wonder if
that's the issue.
 
Dim thisDataAdapter As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter("SELECT * FROM Sessions", OleDbConnection1)

thisDataAdapter.InsertCommand = New
OleDb.OleDbCommand("INSERT INTO Sessions (Notes) VALUES(?) ",
OleDbConnection1)

thisDataAdapter.InsertCommand.Parameters.Add("Notes",
OleDbType.VarChar, 15, "Notes")

Dim thisDataset As DataSet = New DataSet()
thisDataAdapter.Fill(thisDataset, "Sessions")

Dim thisTable As New DataTable()

thisTable = thisDataset.Tables("Sessions")

Dim cRow As DataRow = thisDataset.Tables(0).NewRow()
cRow("Notes") = "Yadda"
thisDataset.Tables(0).Rows.Add(cRow)
thisDataAdapter.Update(thisDataset, "Sessions")
 
Probably.
Write the same query in Access and see if it will run.
If not, there is no way the code version will run.
 
Hi Curt,

Show us the (obfuscated) select string you are using with this example, I
see nothing wrong in the sample you showed.

Cor
 
Curt Emich said:
Dim thisDataAdapter As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter("SELECT * FROM Sessions", OleDbConnection1)

thisDataAdapter.InsertCommand = New
OleDb.OleDbCommand("INSERT INTO Sessions (Notes) VALUES(?) ",
OleDbConnection1)

thisDataAdapter.InsertCommand.Parameters.Add("Notes",
OleDbType.VarChar, 15, "Notes")

Dim thisDataset As DataSet = New DataSet()
thisDataAdapter.Fill(thisDataset, "Sessions")

Dim thisTable As New DataTable()

thisTable = thisDataset.Tables("Sessions")

Dim cRow As DataRow = thisDataset.Tables(0).NewRow()
cRow("Notes") = "Yadda"
thisDataset.Tables(0).Rows.Add(cRow)
thisDataAdapter.Update(thisDataset, "Sessions")

That's not a short but complete program. It's short, but it's not
complete. Please read the link I posted.
 
Back
Top