Increase value by 1. How to do this?

S

Shapper

Hello,

I have a database table with 2 fields: [id] and [value];

I need to create a function which increases by 1 the number in [value]
field for a certain id.

In this moment I have the following:

Private Sub Vote()

' Set Connection
Dim connectionString As String = AppSettings("connectionString")
Dim dbConnection As IDbConnection =
NewOleDbConnection(connectionString)

' Set Query and Command
Dim queryString As String = "SELECT [t_query].* FROM [t_query] WHERE
([t_query].[id] = @id)"
Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

' Add Parameter
dbCommand.Parameters.Add(New OleDbParameter("@id", id))

' Update value ???
dbConnection.Open()
Try
?????
Finally
dbConnection.Close()
End Try

End Sub

I need to know how to increase the [value] number by 1.

Thanks,
Miguel
 
R

Richard Myers

Whats this got to do with ASP.NET?

To do this in code just execute a scalar and type to the appropriate numeric
type then add one and send an update back to the database. Although you
could just as easily do this in SQL.

Richard
 
S

Shapper

Hi,

I don't know if I am getting it.
My first idea was to load the record [value] field using a datareader
and place it in a variable. Then I increase the variable's value by 1
and finally I update my record.

Well, this is an idea. But is this the best way?

When you say to use SQL you say a procedure? I am using Access?

Thanks,
Miguel

Whats this got to do with ASP.NET?

To do this in code just execute a scalar and type to the appropriate numeric
type then add one and send an update back to the database. Although you
could just as easily do this in SQL.

Richard

Hello,

I have a database table with 2 fields: [id] and [value];

I need to create a function which increases by 1 the number in [value]
field for a certain id.

In this moment I have the following:

Private Sub Vote()

' Set Connection
Dim connectionString As String = AppSettings("connectionString")
Dim dbConnection As IDbConnection =
NewOleDbConnection(connectionString)

' Set Query and Command
Dim queryString As String = "SELECT [t_query].* FROM [t_query] WHERE
([t_query].[id] = @id)"
Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

' Add Parameter
dbCommand.Parameters.Add(New OleDbParameter("@id", id))

' Update value ???
dbConnection.Open()
Try
?????
Finally
dbConnection.Close()
End Try

End Sub

I need to know how to increase the [value] number by 1.

Thanks,
Miguel
 
R

Richard Myers

Yep its quite simple.

UPDATE MyTable SET MyTable.MyCol = (MyTable.MyCol+1) WHERE
(((MyTable.MyOtherCol)=5));

Obviously you can drop/enhance the criteria as required.

Richard


Shapper said:
Hi,

I don't know if I am getting it.
My first idea was to load the record [value] field using a datareader
and place it in a variable. Then I increase the variable's value by 1
and finally I update my record.

Well, this is an idea. But is this the best way?

When you say to use SQL you say a procedure? I am using Access?

Thanks,
Miguel

Whats this got to do with ASP.NET?

To do this in code just execute a scalar and type to the appropriate numeric
type then add one and send an update back to the database. Although you
could just as easily do this in SQL.

Richard

Hello,

I have a database table with 2 fields: [id] and [value];

I need to create a function which increases by 1 the number in [value]
field for a certain id.

In this moment I have the following:

Private Sub Vote()

' Set Connection
Dim connectionString As String = AppSettings("connectionString")
Dim dbConnection As IDbConnection =
NewOleDbConnection(connectionString)

' Set Query and Command
Dim queryString As String = "SELECT [t_query].* FROM [t_query] WHERE
([t_query].[id] = @id)"
Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

' Add Parameter
dbCommand.Parameters.Add(New OleDbParameter("@id", id))

' Update value ???
dbConnection.Open()
Try
?????
Finally
dbConnection.Close()
End Try

End Sub

I need to know how to increase the [value] number by 1.

Thanks,
Miguel
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top