SQLDataSource Values

T

TJHerman

Is there any way to refer to the specific field values in an sqldatasource in
a formview without doing the sqldataadapater, datatable, etc.?
 
P

Phillip Williams

You can access the fields values through the command object which is passed
to the event handlers. For example one might add to the markup:
OnSelected ="sqldsOrderDetail_Selected"

and then during handling the Selected event, one might write:

void sqldsOrderDetail_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
//get a reference to the command object used by the SqlDataSource
System.Data.Common.DbCommand command = e.Command;
//you can access the parameter value
Response.Write(command.Parameters["@OrderID"].Value.ToString());
}
 
T

TJHerman

Thank you very much! I will definitely experiment with this! I'm new to the
dotnet but with individuals like you willing to share you knowledge, I'm very
encouraged!
 
T

TJHerman

You wouldn't happen to know how this is written in VB? (I'm really pushing my
luck!)

Phillip Williams said:
You can access the fields values through the command object which is passed
to the event handlers. For example one might add to the markup:
OnSelected ="sqldsOrderDetail_Selected"

and then during handling the Selected event, one might write:

void sqldsOrderDetail_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
//get a reference to the command object used by the SqlDataSource
System.Data.Common.DbCommand command = e.Command;
//you can access the parameter value
Response.Write(command.Parameters["@OrderID"].Value.ToString());
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


TJHerman said:
Is there any way to refer to the specific field values in an sqldatasource in
a formview without doing the sqldataadapater, datatable, etc.?
 
P

Phillip Williams

No problem. You are welcome. It would be great if every poster indicates the
development platform and language they are using within the body of the
question (e.g. ASP.NET2.0 VB would make the response more relevant)

'In this event-handling you access the parameters in the SqlDataSource
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As
SqlDataSourceStatusEventArgs)
Dim command As System.Data.Common.DbCommand = e.Command
'you can access the parameter value
If command.Parameters.Count > 0 AndAlso Not
command.Parameters("PK_ID") Is Nothing Then
Response.Write(command.Parameters("@PK_ID").Value.ToString())
End If

End Sub
'if you want to access any field value within the retrieved data then
use the DataItem
'upon handling the FormView.DataBound event
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim frmV As FormView = DirectCast(sender, FormView)
Dim drv As System.Data.DataRowView = DirectCast(frmV.DataItem,
System.Data.DataRowView)
Response.Write(drv("Company").ToString())
End Sub--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


TJHerman said:
You wouldn't happen to know how this is written in VB? (I'm really pushing my
luck!)

Phillip Williams said:
You can access the fields values through the command object which is passed
to the event handlers. For example one might add to the markup:
OnSelected ="sqldsOrderDetail_Selected"

and then during handling the Selected event, one might write:

void sqldsOrderDetail_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
//get a reference to the command object used by the SqlDataSource
System.Data.Common.DbCommand command = e.Command;
//you can access the parameter value
Response.Write(command.Parameters["@OrderID"].Value.ToString());
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


TJHerman said:
Is there any way to refer to the specific field values in an sqldatasource in
a formview without doing the sqldataadapater, datatable, etc.?
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top