473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OdbcCommandBuilder

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
Nov 16 '05 #1
2 4040
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

"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:ir********************@giganews.com...
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

Nov 16 '05 #2
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

"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:ir********************@giganews.com...
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David P. Donahue | last post by:
I'm using the following code to add a row to a table (for holding images) in my database (obtained from http://www.codeproject.com/aspnet/image_asp.asp?df=100&forumid=38225&select=1038401): ...
0
by: simtin | last post by:
Hi guys. I'm using a DataSet, a OdbcDataAdapter, beeing constructed by pubDA_URL = new OdbcDataAdapter()( new OdbcCommand("select * from urls where project=" + id, pubDB) );
0
by: ehmy | last post by:
Hello. I find OdbcCommandBuilder can not work properly when prepare command for Sybase ASE Server 12.0. I need to access Sybase ASE Server 12.0, but Oledb provider provided by Sybase can not...
5
by: Peter W Johnson | last post by:
Hi Guys, I am having problems getting the following code to update an Access table. I get the following error:- An unhandled exception of type 'System.NullReferenceException' occurred in...
3
by: Peter W Johnson | last post by:
Hi guys, I have the following code which I feel runs slow. I have tried to include de-referencing variables and releasing unmanaged resources. Am I doing the right thing or is there a better way...
1
by: Hendri Adriaens | last post by:
Hi, I try to run this: OdbcDataAdapter odbcDA = new OdbcDataAdapter("select * from job_1", odbcCon); DataTable dataTable = new DataTable(); odbcDA.Fill(dataTable);...
2
Elnath
by: Elnath | last post by:
im connecting to a DataBase tru ODBC, i need to insert new records (rows) therefore i want the InsertCommand to be generated by my CommbadBuilder. This solution however is aint working, the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.