How to increase this value by 1?

  • Thread starter Thread starter Miguel Dias Moura
  • Start date Start date
M

Miguel Dias Moura

Hello,

I have a dataset (users) on an ASP.NET/VB page (detail.aspx).

A record on this dataset (users) has 3 fields: "id", "username",
"visits".

The page detail.aspx is called with a variable value in the URL, such
as:
detail.aspx?user=john

I want to increase the value in "visits" field of the record which
"username" is equal to "user".

Example:

id username visits
....
10 helen 120
11 john 400
12 bird 52
....

So when I call the page with "detail.aspx?user=john", the number in
"visits" of record 11 (username=john) will be increase to 401.

Can someone tell me how to do this?

Thanks,
Miguel
 
Hi Miguel,
You can query the dataset for that record using Select and increment the
value.
Dim strUser As String = Request.QueryString("user")
Dim dr As DataRow()
dr = dsusers.Tables(0).Select("Name='" & strUser & "'")
'Since username is unique hopefully u get only one row.
dr(0).Item(2) = dr(0).Item(2) + 1
HTH
srini
 
string userName=Request.QueryString("user");

and then run a query like this

"UPDATE TABLENAME SET VISITS=VISITS+1 WHERE USERNAME='" + userName + "' ";

It's better if you use a prameterized command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top