By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Using dataadpater.Update(datatable) when the da is from a file

P: n/a
I want to update records from a csv file.

I do this in a button click:

//Create Adapters
da = new OdbcDataAdapter("Select * FROM test.csv", conn);

//Fill a data table
da.Fill(dt);

//Populate grid with file data
dataGrid1.DataSource = dt;

//Builder
csvBuilder = new OdbcCommandBuilder(da);

// Close the connection
conn.Close();

In another button click I delete some rows:

I loop thru the datarow and call dr.Delete() on the appropiate row and then
call dataGrid1.Refresh() which updates the grid with the remaining rows.

In another button click I want to update the test.csv file I pulled the data
from by doing this:

da.Update(dt);

But it throws this exception:

Additional information: Dynamic SQL generation for the DeleteCommand is not
supported against a SelectCommand that does not return any key column
information.

Does this mean my file needs to have a primary key. It does not, so how do I
update the file.

Thanks


Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Yes, you're going to need a key in order to run an Update w/ CommandBUilder-
regardless of the source.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
<Pa******@newsgroup.nospam> wrote in message
news:E4**********************************@microsof t.com...
I want to update records from a csv file.

I do this in a button click:

//Create Adapters
da = new OdbcDataAdapter("Select * FROM test.csv", conn);

//Fill a data table
da.Fill(dt);

//Populate grid with file data
dataGrid1.DataSource = dt;

//Builder
csvBuilder = new OdbcCommandBuilder(da);

// Close the connection
conn.Close();

In another button click I delete some rows:

I loop thru the datarow and call dr.Delete() on the appropiate row and then call dataGrid1.Refresh() which updates the grid with the remaining rows.

In another button click I want to update the test.csv file I pulled the data from by doing this:

da.Update(dt);

But it throws this exception:

Additional information: Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column
information.

Does this mean my file needs to have a primary key. It does not, so how do I update the file.

Thanks


Nov 16 '05 #2

P: n/a
Is there any other way for me to update the csv file without having a key?

or is there a way for me to add a key to the csv file, and then use the
da.update(dt). The key can't be a unique key.

Paul

"W.G. Ryan eMVP" wrote:
Yes, you're going to need a key in order to run an Update w/ CommandBUilder-
regardless of the source.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
<Pa******@newsgroup.nospam> wrote in message
news:E4**********************************@microsof t.com...
I want to update records from a csv file.

I do this in a button click:

//Create Adapters
da = new OdbcDataAdapter("Select * FROM test.csv", conn);

//Fill a data table
da.Fill(dt);

//Populate grid with file data
dataGrid1.DataSource = dt;

//Builder
csvBuilder = new OdbcCommandBuilder(da);

// Close the connection
conn.Close();

In another button click I delete some rows:

I loop thru the datarow and call dr.Delete() on the appropiate row and

then
call dataGrid1.Refresh() which updates the grid with the remaining rows.

In another button click I want to update the test.csv file I pulled the

data
from by doing this:

da.Update(dt);

But it throws this exception:

Additional information: Dynamic SQL generation for the DeleteCommand is

not
supported against a SelectCommand that does not return any key column
information.

Does this mean my file needs to have a primary key. It does not, so how do

I
update the file.

Thanks



Nov 16 '05 #3

P: n/a
Hi Paul,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to update a csv file. If there
is any misunderstanding, please feel free to let me know.

Generally, when we need to update a database, we need a primary key column
to let the command builder generate update commands for you.

However, as far as I know, the Text driver for accessing .csv files is
readonly. It doesn't support updating, which means whether we have a
primary key or not, we cannot update the data source.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.