SQLDataSource Values

Discussion in 'ASP .Net Web Controls' started by TJHerman, Jun 28, 2006.

  1. TJHerman

    TJHerman Guest

    Is there any way to refer to the specific field values in an sqldatasource in
    a formview without doing the sqldataadapater, datatable, etc.?
    TJHerman, Jun 28, 2006
    #1
    1. Advertising

  2. 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" wrote:

    > Is there any way to refer to the specific field values in an sqldatasource in
    > a formview without doing the sqldataadapater, datatable, etc.?
    Phillip Williams, Jun 29, 2006
    #2
    1. Advertising

  3. TJHerman

    TJHerman Guest

    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!

    "TJHerman" wrote:

    > Is there any way to refer to the specific field values in an sqldatasource in
    > a formview without doing the sqldataadapater, datatable, etc.?
    TJHerman, Jun 29, 2006
    #3
  4. TJHerman

    TJHerman Guest

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

    "Phillip Williams" wrote:

    > 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" wrote:
    >
    > > Is there any way to refer to the specific field values in an sqldatasource in
    > > a formview without doing the sqldataadapater, datatable, etc.?
    TJHerman, Jun 29, 2006
    #4
  5. 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" wrote:

    > You wouldn't happen to know how this is written in VB? (I'm really pushing my
    > luck!)
    >
    > "Phillip Williams" wrote:
    >
    > > 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" wrote:
    > >
    > > > Is there any way to refer to the specific field values in an sqldatasource in
    > > > a formview without doing the sqldataadapater, datatable, etc.?
    Phillip Williams, Jun 29, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew
    Replies:
    3
    Views:
    2,862
    Andrew
    Apr 1, 2004
  2. =?Utf-8?B?RWQ=?=
    Replies:
    0
    Views:
    3,251
    =?Utf-8?B?RWQ=?=
    Apr 18, 2006
  3. ASMJ
    Replies:
    0
    Views:
    571
  4. Ganesh

    get sqldatasource field values

    Ganesh, Jul 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    3,639
    nahid
    Jul 15, 2007
  5. S_K
    Replies:
    0
    Views:
    440
Loading...

Share This Page