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.AppS ettings["m yDB"];
SqlConnection myConnection = new SqlConnection(strConnectio n);
SqlCommand myCommand = new SqlCommand("CSP_Update_Hit Counter", myConnection);
myCommand.CommandType = CommandType.StoredProcedur e;
myCommand.Parameters.Add(" @myPage", SqlDbType.Text).Value = strMyPage;
myCommand.Connection.Open( );
myCommand.ExecuteNonQuery( );
myCommand.Connection.Close ();
myCommand.Connection.Dispo se();
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.
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.AppS
SqlConnection myConnection = new SqlConnection(strConnectio
SqlCommand myCommand = new SqlCommand("CSP_Update_Hit
myCommand.CommandType = CommandType.StoredProcedur
myCommand.Parameters.Add("
myCommand.Connection.Open(
myCommand.ExecuteNonQuery(
myCommand.Connection.Close
myCommand.Connection.Dispo
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the response, abhi376.
anyone else?
anyone else?
Hey shozam ,
you need anything let me know
you need anything let me know
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
con.Open()
For opening the connection.