Question using a field in a database to keep a counter

wmdaniels

Member
Joined
Sep 19, 2011
Messages
6
Programming Experience
Beginner
hi,



im using vb..net 2008 and sql 2008. i have a column in the database to keep a count of the number
of times a item is selected in the combo box in my form. how do i update that counter field?

thanks
 
A database seems an odd place to store that information, unless you need one value for multiple clients. If it's only for one user then it would make more sense to use My.Settings. So, do you need this counter to update for one user or multiple users? If it is multiple users and you stick with the database then it's simply a matter of executing an UPDATE statement and setting your field to its current value plus one. As for how to access databases in general, there is lots of information already out there on the web on ADO.NET and data access. You should read up and learn all the basic principles and not just a solution to this one specific problem.
 
In that case I guess maybe a database is the right option. As for an example, that's not what you're asking for. You're asking for me to write your code for you. If you want examples then there are lots of them already on the web. You've apparently made no effort to find any of them. Here's the first step:

vb.net sql server update record - Google Search

It takes no programming experience or knowledge to type some keywords into a search engine. Once you've made an effort to find and use the information that's already out there, post back if you have issues. I will be very happy to help someone who has tried to help themselves. I'm not here to do anyone's work for them though. I'm here to help them do it themselves.
 
I have been searching and so far this is what i came up with:


Private Sub btnsubmitdemo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmitdemo.Click




SurveydbDataSet.Tables(
"demooptions").Rows(cmboptions.SelectedItem).Item(3) = +1


End Sub

however the row value i cannot seem to get right.

 
You don't need a DataTable. You just need to execute an UPDATE statement against the database. There's no need to retrieve anything. Look for ExecuteNonQuery, which is the method you'd call to execute your SQL.
 
If you have the SQL management console, you can test your SQL query first.

UPDATE table SET column=value

Have you managed to connect to the SQL DB from your VB.net app yet?
 
item=combobox.selecedindex-1 or combobox.selecedindex, depending... Test It.

slq statement="Update [tablename] SET MyCounter=MyCounter+1"

Hope It Helps.
 
Back
Top