SQLDataSource\AccessingData\Columns

G

gh

I am using a SQLDataSource in an ASP.NET 2.0 web app. I want to loop
through datarows, in the result set, to read the and write values to
acouple of the fields. I can' t locate any properties for the datarow
in the control. How do I access the datarow properties in this control
to loop through or is there another way.

foreach(datarow dr in ...)
{
x = dr["Amt"];
dr["Bal"] = x * .06;
}

TIA
 
G

gh

Eliyahu:

Here is the error I get when using the code on your site. I have a
button on the aspx page and I am trying to do a foreach in the click event.

foreach (DataRow dw in this.dt)
{
......

CS1579: foreach statement cannot operate on variables of type
'System.Data.DataTable' because 'System.Data.DataTable' does not contain
a public definition for 'GetEnumerator'

Any ideas what would cause this error?


TIA
 
G

gh

Eliyahu:


Below is the error I get when I click the button. I know data binding
will sometimes throw this error, but since the data table is in memory,
do I have to databind it?

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:

Line 31:
Line 32:
Line 33: foreach (DataRow dw in this.dt.Rows)

[NullReferenceException: Object reference not set to an instance of an
object.]
_Default.Button1_Click(Object sender, EventArgs e) in c:\Documents
and Settings\jbarr\My Documents\Visual Studio
2005\WebSites\WebSite3\Default.aspx.cs:33
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


TIA
 
E

Eliyahu Goldin

Apparently this.dt is not set. Check in the debugger.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


gh said:
Eliyahu:


Below is the error I get when I click the button. I know data binding
will sometimes throw this error, but since the data table is in memory, do
I have to databind it?

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:

Line 31:
Line 32:
Line 33: foreach (DataRow dw in this.dt.Rows)

[NullReferenceException: Object reference not set to an instance of an
object.]
_Default.Button1_Click(Object sender, EventArgs e) in c:\Documents and
Settings\jbarr\My Documents\Visual Studio
2005\WebSites\WebSite3\Default.aspx.cs:33
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


TIA

Eliyahu said:
foreach (DataRow dw in this.dt.Rows)

should fix that.
 

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