471,582 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

SQLDataSource\AccessingData\Columns

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
Jan 16 '07 #1
5 5229
SQLDataSource is designed to automate your databinding. You need to take
special measures to work with it programmatically.

I have a blog article that can help you:
http://msmvps.com/blogs/egoldin/arch...atasource.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"gh" <gh@att.netwrote in message
news:Oy**************@TK2MSFTNGP06.phx.gbl...
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

Jan 16 '07 #2
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

Eliyahu Goldin wrote:
SQLDataSource is designed to automate your databinding. You need to take
special measures to work with it programmatically.

I have a blog article that can help you:
http://msmvps.com/blogs/egoldin/arch...atasource.aspx
Jan 16 '07 #3
foreach (DataRow dw in this.dt.Rows)

should fix that.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"gh" <gh@att.netwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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

Eliyahu Goldin wrote:
SQLDataSource is designed to automate your databinding. You need to take
special measures to work with it programmatically.

I have a blog article that can help you:
http://msmvps.com/blogs/egoldin/arch...atasource.aspx

Jan 16 '07 #4
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.RaisePostBackEven t(String
eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
TIA

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

should fix that.
Jan 16 '07 #5
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" <gh@att.netwrote in message
news:Oo**************@TK2MSFTNGP03.phx.gbl...
>
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.RaisePostBackEven t(String
eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
TIA

Eliyahu Goldin wrote:
>foreach (DataRow dw in this.dt.Rows)

should fix that.

Jan 17 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

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.