473,395 Members | 1,689 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,395 software developers and data experts.

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

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
3 2379
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: rob | last post by:
Hey, I need to update a row in one table with a row (most but not all columns) from another table. This sounds like there should be a really easy way to do this. I've seen there's FROM in the...
1
by: Primerov | last post by:
Why i cannot update from another form? I have an update function called UpdateData that works otherwise,but not from another form. Why is it so? I am trying to update tables from the form F1.There...
2
by: Thomas | last post by:
I have a Informix Database on Solaris and a SQL database. I need to update from Informix to SQL daily. Is there any easy way of doing it? BTW, I tried to use OleDbDataAdpater.Update to do the job....
9
by: mike_li | last post by:
We are considering to update from V8.1 Fixpak 8 to Fixpak 9. Operating System Information: OSName: AIX NodeName: mdxxx01, mdxxx02, mdxxx03, mdxxx04 Version: 5 Release: 2 64 bits and DB2...
1
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the...
8
by: Richard | last post by:
Hello! I have this piece of SQL code: UPDATE a SET Field1 = c.Field1 FROM a INNER JOIN b ON a.GUID1 = b.GUID1 INNER JOIN c ON b.GUID2 = c.GUID2 WHERE c.Type = 1
0
by: bbqbbq | last post by:
Hi All, I need find a way to dynamicly fill a DetailsView using DataTable. Can you give me a sample? Thanks a lot!
1
by: vinodkus | last post by:
dear sir/madam Can any one help me how to connect ASP and MS ACCESS using FILE DSN. Thanks in Advance vinod
1
by: jaredciagar | last post by:
Hi guys...can you help me please.... I'm using ASP.net, MSSQL 2005 and VB Script I have don't know how to bind data in gridview control from database. I want also to allow paging in gridview...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.