none
update data with number of times viewed RRS feed

  • Question

  • Everytime someone views detailed stored data I want to keep a count. I first thought of adding a number field in the table and increasing it everytime the data was viewed, but having trouble with the code. Any ideas and is this the best way?
    Monday, July 13, 2009 7:21 AM

Answers

  • To execute action stored procedure that only changes data, you need to use ExecuteNonQuery method of SqlCommand. You do not need to use SqlDataSource object for that. Here is the sample of using ExecuteNonQuery

    http://support.microsoft.com/kb/308049
    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Yichun_Feng Friday, August 7, 2009 5:54 AM
    Tuesday, July 14, 2009 10:17 AM
    Moderator

All replies

  • Do you need to know the count or the fact that someone looked into the data? If you need to log the fact, you might run SQL Server profiler that would log specific events on database server. Otherwise you would need to store count information, since there is no automatic way to count it.
    Val Mazur (MVP) http://www.xporttools.net
    Monday, July 13, 2009 10:07 AM
    Moderator
  • Yes I do need to know the count as I want to display it for users to see. What would be the best way to code it. I started with (but as i'm new to this am stuck).

    Dim ContactsData As New SqlDataSource() 

     ContactsData.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure

    ContactsData.ConnectionString = ConfigurationManager.ConnectionStrings("myconnection").ToString() ContactsData.UpdateParameters.Add("NumberViews")

    ContactsData.UpdateCommand ="NumberViewsUpdate"

    ContactsData.Update()


    ------and proceedure,
    dbo.NumberViewsUpdate

    @NumberViews

     int,
    @LoginID varchar
    (50)
    as
     
    update [ContactDetails] 
     
    set [NumberViews] = @NumberViews + 1 
     
    where LoginID = @LoginID 

     

    • Edited by roger1000cc Monday, July 13, 2009 11:59 AM error on paste order
    Monday, July 13, 2009 11:54 AM
  • To execute action stored procedure that only changes data, you need to use ExecuteNonQuery method of SqlCommand. You do not need to use SqlDataSource object for that. Here is the sample of using ExecuteNonQuery

    http://support.microsoft.com/kb/308049
    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Yichun_Feng Friday, August 7, 2009 5:54 AM
    Tuesday, July 14, 2009 10:17 AM
    Moderator