datareader

G

Guest

I have used SqlDataReader to bind to a datagrid of my webForm.It's working finely

But when I used the DataReader for my datagrid on my winform , it's giving an error

why so?
 
M

Miha Markic

Hi reiks,

reiks said:
I have used SqlDataReader to bind to a datagrid of my webForm.It's working finely.

But when I used the DataReader for my datagrid on my winform , it's giving an error.

why so?

That's because web binding is different thatn win binding.
In web, binding is unidirectional - the data is just read from datasource -
that's why forward only datareader is fine.
However, win binding is bidirectional - you need a container for your data.
In the ado.net case that container is normally DataTable which is normally
filled using DataAdapter.Fill method.
 
R

Rob Richardson

Miha and Reiks,

I am a newbie in the .Net world, although I have been a professional VC++/VB
programmer for a long time. Miha's answer doesn't make sense to me. I
understand that web binding would use a unidirectional thing like a
DataReader, but if the Windows form has the same logic behind it, I would
think that a DataReader would work just fine. The data would still be read
from top to bottom and would not be changed. Or is the data being changed?

Reik, could you tell us what error you are seeing?

Rob
 
M

Marina

The idea is, the grid needs an object it can write back to. And since a
datareader is read only forward only, that's not possible, so you get an
error.
 
M

Miha Markic

Hi Rob,

As marina said, grid doesn't hold any data.
Everything is stored in datasource.
 
W

William \(Bill\) Vaughn

I'm with you Rob, it doesn't make sense to me either. Why can't you one-way
bind in Windows Forms like you can in Web forms? Well, it's because they
didn't want to implement it. It's there in the next version (Whidbey).
In VB6 binding was (usually, but not always) a two-way deal. When you
changed the bound control the database was changed (when you used a Data
Source control). In VB.NET more of the "updating" responsibilities are up to
you. I think this is better because my code fit my situations better than
the OSFA (One size fits all) code that ADO classic used.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

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