Simple asp.net question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PCL

    #1

    Simple asp.net question

    I am new to asp.net and am having a hard time with what i would usually do
    with a recordset. I have a simple query that returns a record - how can i
    get that record value into a variable after i execute the query:

    select Max(DailyPOnumb er) + 1 as MaxPO from tblPurchaseOrde rs

    i used to be able to do something similar to
    MaxNo=rs("MaxNo ")

    any help would be appreciated
  • [Alan Flores]

    #2
    RE: Simple asp.net question

    try this :

    on the datareader
    do while reader.read
    maxno = reader("maxno")
    loop

    --

    "PCL" wrote:
    [color=blue]
    > I am new to asp.net and am having a hard time with what i would usually do
    > with a recordset. I have a simple query that returns a record - how can i
    > get that record value into a variable after i execute the query:
    >
    > select Max(DailyPOnumb er) + 1 as MaxPO from tblPurchaseOrde rs
    >
    > i used to be able to do something similar to
    > MaxNo=rs("MaxNo ")
    >
    > any help would be appreciated[/color]

    Comment

    • PCL

      #3
      RE: Simple asp.net question

      Thank You for your help - this got me a little further.

      I Dimensioned maxno as an objext

      i tried making it an integer and it errored out. The problem is now that it
      is an object i am not able to work with the value - i tried assigning it to a
      text box and i got the following error:

      Exception Details: System.InvalidC astException: Cast from type
      'SqlDataReader' to type 'String' is not valid.

      Source Error:


      Line 238: End If
      Line 239: Label11.Text = Sql
      Line 240: lblextra.Text = MaxPO <-----Problem line
      Line 241: End Sub
      Line 242:End Class



      "[Alan Flores]" wrote:
      [color=blue]
      > try this :
      >
      > on the datareader
      > do while reader.read
      > maxno = reader("maxno")
      > loop
      >
      > --
      >
      > "PCL" wrote:
      >[color=green]
      > > I am new to asp.net and am having a hard time with what i would usually do
      > > with a recordset. I have a simple query that returns a record - how can i
      > > get that record value into a variable after i execute the query:
      > >
      > > select Max(DailyPOnumb er) + 1 as MaxPO from tblPurchaseOrde rs
      > >
      > > i used to be able to do something similar to
      > > MaxNo=rs("MaxNo ")
      > >
      > > any help would be appreciated[/color][/color]

      Comment

      • Hermit Dave

        #4
        Re: Simple asp.net question

        try MaxPo.ToString( );
        or convert.ToStrin g(MaxPO);

        --

        Regards,

        Hermit Dave (D'way)
        "Listen, three eyes, Don't you try to outweird me. I get stranger things than you free with my breakfast cereal."


        (I hear what you're saying.. but lets try it my way first)

        "PCL" <PCL@discussion s.microsoft.com > wrote in message
        news:552FEEDF-7BE1-416B-93CB-666035463634@mi crosoft.com...[color=blue]
        > Thank You for your help - this got me a little further.
        >
        > I Dimensioned maxno as an objext
        >
        > i tried making it an integer and it errored out. The problem is now that[/color]
        it[color=blue]
        > is an object i am not able to work with the value - i tried assigning it[/color]
        to a[color=blue]
        > text box and i got the following error:
        >
        > Exception Details: System.InvalidC astException: Cast from type
        > 'SqlDataReader' to type 'String' is not valid.
        >
        > Source Error:
        >
        >
        > Line 238: End If
        > Line 239: Label11.Text = Sql
        > Line 240: lblextra.Text = MaxPO <-----Problem line
        > Line 241: End Sub
        > Line 242:End Class
        >
        >
        >
        > "[Alan Flores]" wrote:
        >[color=green]
        > > try this :
        > >
        > > on the datareader
        > > do while reader.read
        > > maxno = reader("maxno")
        > > loop
        > >
        > > --
        > >
        > > "PCL" wrote:
        > >[color=darkred]
        > > > I am new to asp.net and am having a hard time with what i would[/color][/color][/color]
        usually do[color=blue][color=green][color=darkred]
        > > > with a recordset. I have a simple query that returns a record - how[/color][/color][/color]
        can i[color=blue][color=green][color=darkred]
        > > > get that record value into a variable after i execute the query:
        > > >
        > > > select Max(DailyPOnumb er) + 1 as MaxPO from tblPurchaseOrde rs
        > > >
        > > > i used to be able to do something similar to
        > > > MaxNo=rs("MaxNo ")
        > > >
        > > > any help would be appreciated[/color][/color][/color]


        Comment

        • PCL

          #5
          Re: Simple asp.net question

          My ongoing saga to return a value from a stored procedure - i switched from
          using data reader to using a dataadapter. I now am able to assign a textbox
          the number of records returned by the Stored procedure with:

          txtExtra.Text = DS.Tables("PO") .Rows.Count
          it returns 1 which is what i expect - i want to actually store the value of
          the stored procedure returns (it is a simple SQL - Select Max(po) from PODB)

          i tried the following line and it returns nothing:
          txtExtra.Text = DS.Tables("PO") .Rows(0).Item(0 ).ToString()

          i tried
          txtExtra.Text = DS.Tables("PO") .Rows(1).Item(1 ).ToString()
          and i get an error which tells me there is now row 1.

          Any help would be greatly appreciated - it is frustrating - i feel i am
          very close yet so far away....



          "Hermit Dave" wrote:
          [color=blue]
          > try MaxPo.ToString( );
          > or convert.ToStrin g(MaxPO);
          >
          > --
          >
          > Regards,
          >
          > Hermit Dave (D'way)
          > http://hdave.blogspot.com
          >
          > (I hear what you're saying.. but lets try it my way first)
          >
          > "PCL" <PCL@discussion s.microsoft.com > wrote in message
          > news:552FEEDF-7BE1-416B-93CB-666035463634@mi crosoft.com...[color=green]
          > > Thank You for your help - this got me a little further.
          > >
          > > I Dimensioned maxno as an objext
          > >
          > > i tried making it an integer and it errored out. The problem is now that[/color]
          > it[color=green]
          > > is an object i am not able to work with the value - i tried assigning it[/color]
          > to a[color=green]
          > > text box and i got the following error:
          > >
          > > Exception Details: System.InvalidC astException: Cast from type
          > > 'SqlDataReader' to type 'String' is not valid.
          > >
          > > Source Error:
          > >
          > >
          > > Line 238: End If
          > > Line 239: Label11.Text = Sql
          > > Line 240: lblextra.Text = MaxPO <-----Problem line
          > > Line 241: End Sub
          > > Line 242:End Class
          > >
          > >
          > >
          > > "[Alan Flores]" wrote:
          > >[color=darkred]
          > > > try this :
          > > >
          > > > on the datareader
          > > > do while reader.read
          > > > maxno = reader("maxno")
          > > > loop
          > > >
          > > > --
          > > >
          > > > "PCL" wrote:
          > > >
          > > > > I am new to asp.net and am having a hard time with what i would[/color][/color]
          > usually do[color=green][color=darkred]
          > > > > with a recordset. I have a simple query that returns a record - how[/color][/color]
          > can i[color=green][color=darkred]
          > > > > get that record value into a variable after i execute the query:
          > > > >
          > > > > select Max(DailyPOnumb er) + 1 as MaxPO from tblPurchaseOrde rs
          > > > >
          > > > > i used to be able to do something similar to
          > > > > MaxNo=rs("MaxNo ")
          > > > >
          > > > > any help would be appreciated[/color][/color]
          >
          >
          >[/color]

          Comment

          Working...