OdbcCommandBuilder

P

Pete Davis

I'm trying to add a new record to an access table. I'm using Odbc because
I'm deploying it on a web site using MySql. Performance isn't an issue at
all.

Anyway, I've never done Odbc and I'm not sure if that's the problem or what
is. My code is pretty straight-forward:

string query = "SELECT * from NewsItem";
using (OdbcConnection conn = new OdbcConnection(_connectionString))
{
OdbcDataAdapter adapter = new OdbcDataAdapter(query, conn);
OdbcCommandBuilder cb = new OdbcCommandBuilder(adapter);
conn.Open();
DataSet ds = new DataSet();
adapter.Fill(ds);
DataTable table = ds.Tables[0];
DataRow dr = table.NewRow();
dr.BeginEdit();
dr["PostDate"] = item.PostDate.ToString();
...
table.AcceptChanges();
adapter.Update(ds);
}

I've also never used a commandbuilder (call me crazy, but I usually do the
commands by hand). Anyway, this all seems to follow what I've seen in the
MSDN, but nothing's happening. By "Nothing's happening", I mean, nothing is
getting inserted into the table and no errors or exceptions appear.

The CommandBuilder doesn't appear to be creating an insert, update, or
delete statement either in itself or the DataAdapter.

I've tried with dr.BeginEdit() and/or table.AcceptChanges() commented out.
Doesn't seem to matter.

The Update() returns 0.

I've tried filling in the column names instead of doing a "select *" but
that doesn't make a difference.

My _connectionString is "DSN=mydsn". The DSN exists and I believe is
configured properly.

I'm stumped. Surely it's something pretty stupid.

Pete
 
P

Pete Davis

I'm missing the table.Rows.Add(dr) in there, but that stil doesn't make a
difference. The problem still appears to be the CommandBuilder not
generating the statements.

Pete
 
P

Pete Davis

Found the problem. It appears to have been an issue with the DSN. I used a
different driver and it worked fine. Access Trieber instead of just Access.
What's the difference? Anyone know?

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top