DataTable Load Issue

K

Kurt

Hi,

I am having some trouble with a custom IDataReader and the DataTable.Load
method when dealing with NULL data, specifically, if a data value is changed
in a loaded DataTable from say a double value of 56.23 to a NULL value, the
source is updated and the DataTable load is called again using IDataReader,
the null value will not be loaded into the updated DataTable, the original
value of 56.23 stays. If I call DataTable.Rows.Clear() prior to doing the
load, the data is accurately reflected. I did this to verify the data was
passing through the IDataReader class successfully. Although we are using
this as a work around, it would be preferable to do the load without the
clear, as this prevents the UI grids from clearing and re-loading.

I verified that the IDataReader is returning a NULL value in the appropriate
column; however, when looking at the final loaded DataTable in the debugger,
that value change is not reflected. I have also tried all of the LoadOptions,
and this did not change the behavior. Finally, I checked the RecordsAffected
property of the IDataReader and this is returning a value > 0, I also tried
setting this to -1, but this also made no difference.

I am not sure what else to try, as something is happening in the DataTable
load process that I do not understand..?
 
C

Cor Ligthert[MVP]

Kurt,
I am not sure what else to try, as something is happening in the DataTable
load process that I do not understand..?
Then why do you not use a DataAdapter.Fill?

Cor
 
K

Kurt

I am sorry, I guess I did not specify that. I am using the
DataTable.Fill(IDataReader) method.
 
C

Cor Ligthert[MVP]

Kurt

Most of us use



dim conn as new Sqlconnection(connectionstring)
dim da as new SqlDataAdapter("Select * from whatever", conn)
dim dt as New DataTable
da.Fill(dt)

in C# a little bit more words and characters but for the rest the same.

SqlConnection conn = new sqlConnectionConnection(connectionstring);
SqlDataAdapter da = new SqlDataAdapter("Select * from whatever", conn);
Dataset dt = new DataTable();
da.Fill(dt);

Cor
 
K

Kurt

I am not using a database, its actually a custom datareader that we are
using to pull data from a defferent type of data source.

We are using the DataCache, a DataTable, and a custom IDataReader to load
the dataset. Somewhere in the DataTable.Fill(IDataReader) method, datavalues
there were set, then reset to null are ignored, dispite the fact the custom
IDataReader returing the correct value.
 
W

William Vaughn

I would have phrased that "many" or "some" or "I" use the SqlDataAdapter.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 
C

Cor Ligthert[MVP]

William,
I would have phrased that "many" or "some" or "I" use the SqlDataAdapter.

What does that mean, sorry to correct you, by me as a not native English
speaker, however for me is this a very bad use of the English language, in a
program language it is even terrible.

If you want to correct me, than you maybe could have written where I know to
go on slippery ground.

'I would have phrased that as "Many including I use the SqlDataAdapter' ".

But that was not what I wanted to say, as I have seen in the dotNet
newsgroup as it is used.

As it is about DataTables, than the TableAdapter including the datareader
has not been a greath success in my idea. Because I have seen here and other
newsgroups that it gives much confusions, which the DBDataAdapter direct (in
the simple form as it is used in the tableadapter) does not.

Be aware this is only about the DataTable, there are other possibilities to
fetch data from the database.

Cor
 

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