TableAdapter returns null for stored proc returning a single value

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

    TableAdapter returns null for stored proc returning a single value

    Hi,

    I have a stored procedure that returns a single value. Example:
    [...]
    SELECT @RowCount = COUNT(*) FROM t WHERE [...]
    RETURN @RowCount

    I created a data set, table adapter, and adapter's method configured for the
    stored proc and as returning a single value. The wizard created an adapter
    method that calls SqlCommand.Exec uteScalar(). The problem is that
    ExecuteScalar() always returns a null object. I have no problem executing
    the stored procedure from outside of asp.net.

    Could someone please let me give me some idea what could be wrong here?

    Thanks,
    Bogdan


  • Waldy

    #2
    Re: TableAdapter returns null for stored proc returning a single value

    Have you set the SqlCommand.Comm andType to StoredProcedure ?

    "bogdan" <bogdan@company .comwrote in message
    news:%23vIBPKYm IHA.1208@TK2MSF TNGP05.phx.gbl. ..
    Hi,
    >
    I have a stored procedure that returns a single value. Example:
    [...]
    SELECT @RowCount = COUNT(*) FROM t WHERE [...]
    RETURN @RowCount
    >
    I created a data set, table adapter, and adapter's method configured for
    the stored proc and as returning a single value. The wizard created an
    adapter method that calls SqlCommand.Exec uteScalar(). The problem is that
    ExecuteScalar() always returns a null object. I have no problem executing
    the stored procedure from outside of asp.net.
    >
    Could someone please let me give me some idea what could be wrong here?
    >
    Thanks,
    Bogdan
    >
    >

    Comment

    • bogdan

      #3
      Re: TableAdapter returns null for stored proc returning a single value

      I used TableAdapter Qeury Configuration Wizard and selected "Use existing
      stored procedure".

      "Waldy" <someone@micros oft.comwrote in message
      news:OL5XhSYmIH A.3780@TK2MSFTN GP06.phx.gbl...
      Have you set the SqlCommand.Comm andType to StoredProcedure ?
      >
      "bogdan" <bogdan@company .comwrote in message
      news:%23vIBPKYm IHA.1208@TK2MSF TNGP05.phx.gbl. ..
      >Hi,
      >>
      >I have a stored procedure that returns a single value. Example:
      >[...]
      >SELECT @RowCount = COUNT(*) FROM t WHERE [...]
      >RETURN @RowCount
      >>
      >I created a data set, table adapter, and adapter's method configured for
      >the stored proc and as returning a single value. The wizard created an
      >adapter method that calls SqlCommand.Exec uteScalar(). The problem is
      >that ExecuteScalar() always returns a null object. I have no problem
      >executing the stored procedure from outside of asp.net.
      >>
      >Could someone please let me give me some idea what could be wrong here?
      >>
      >Thanks,
      >Bogdan
      >>
      >>
      >
      >

      Comment

      • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

        #4
        RE: TableAdapter returns null for stored proc returning a single value

        executescaler returns the first column, of the first row, of the first
        resultset. your stored proc does not return any rows, only a return value. to
        get the return value, use ExecuteNonQuery with a returnvalue parameter

        cmd.CommandText = "myproc";
        cmd.CommandType = CommandType.Sto redProcedure;
        SqlParameter param = new SqlParameter("@ returnValue",Sq lDbType.Int);
        param.Direction = ParameterDirect ion.ReturnValue ;
        cmd.Parameters. Add(param);
        cmd.ExecuteNonQ uery();
        int rows = (int) cmd.Parameters( "@returnValue") .Value;


        -- bruce (sqlwork.com)


        "bogdan" wrote:
        Hi,
        >
        I have a stored procedure that returns a single value. Example:
        [...]
        SELECT @RowCount = COUNT(*) FROM t WHERE [...]
        RETURN @RowCount
        >
        I created a data set, table adapter, and adapter's method configured for the
        stored proc and as returning a single value. The wizard created an adapter
        method that calls SqlCommand.Exec uteScalar(). The problem is that
        ExecuteScalar() always returns a null object. I have no problem executing
        the stored procedure from outside of asp.net.
        >
        Could someone please let me give me some idea what could be wrong here?
        >
        Thanks,
        Bogdan
        >
        >
        >

        Comment

        Working...