Thursday, March 22, 2012

Data Retrieval for Reports from Summary table.

Hi,

I have asummary table like this

Field1Field2Field3Field4Field5AAA11value1value2value3value4value5AAB23value6value7value8value9value10BCD14value11value12value13value14value15GFD12value16value17value18value19value20SDL25value21value22value23value24value25AUD56value26value27value28value29value30BER11value31value32value33value34value35

Columns are obviously fixed, but not rows.

I want to show this data using lables and SqlDataReader for report purpose like;

Label1.text=dr("value16").toString()

Label2.text=dr("value28").toString()

Label3.text=dr("value31").toString() etc

Do you have any idea how i can do it or am I approaching it in the wrong way??

Thanks.

Michelle

Hi Michelle,

Are you trying to put the values of the table to a set of Label controls?

If so, you have to use field name as argument, like

Label1.Text = dr("Field1").ToString()

When you need to advance to the next row, you have to call dr.Read(). So the best way is to put this in a loop.

If you want to put the whole table in a gridview, you can use GridView.DataSource = dr directly, and call DataBind(). This will make your GridView bind to the DataReader.

HTH.

No comments:

Post a Comment