Link to home
Start Free TrialLog in
Avatar of shozam
shozam

asked on

incremental update stored procedure return value

hi there; using asp.net (c#, 3.5) i would like to send my stored procedure a value (ie. myPage) and have my stored procedure:

1. select the record that pertains to this value in my hit counter table,
2. update the current stored value by 1
3. return the new value to my .aspx page

here is my existing code:

.aspx.cs:

        string strMyPage= txtMyPage.Text;

        string strConnection = ConfigurationSettings.AppSettings["myDB"];

        SqlConnection myConnection = new SqlConnection(strConnection);

        SqlCommand myCommand = new SqlCommand("CSP_Update_HitCounter", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;

        myCommand.Parameters.Add("@myPage", SqlDbType.Text).Value = strMyPage;

        myCommand.Connection.Open();
        myCommand.ExecuteNonQuery();
        myCommand.Connection.Close();
        myCommand.Connection.Dispose();

stored procedure:

(
@count int,
@myPage varchar(50)
)
AS
UPDATE dbo.tblCount
SET @count = fldCount + 1
WHERE(fldPage= @myPage)
      /* SET NOCOUNT ON */
      RETURN @count

This is my best crack at it but isn't quite right.  Also not sure how to retrieve the returned value in my asp.cs page.

suggestions?  thanks all.
SOLUTION
Avatar of abhi376
abhi376
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
  Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("db").ConnectionString)
        con.Open()

For opening the connection.
Avatar of shozam
shozam

ASKER

thanks for the response, abhi376.  

anyone else?
Hey shozam ,

you need anything let me know
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial