April 29th, 2012, 12:09 PM
Counter in SQL and Database help!
I'm a bit of a 'Newbie' and I'm practising SQL and Databases. I've got a windows form in VS2010 which takes a word from a text box and on a button click, that a word is stored in the database.
I have my database called 'Setup' my table called 'tblpeople' and 2 columns called 'people' and 'occur'
So right now my data values from textbox1 are going into 'people' like it should, but what I want to add is that if a persons name is all ready in 'people' then I want it to NOT add it in again but add a count to the 'occur' column beside it.
so in my data base table it should look like this once i've updated it:
That's only an example since it could be any name i've entered.
Here's my code so far:
note: I've got the string split because it's only names starting with * to get stored.
private void database()
SqlConnection conn = new SqlConnection();
connection.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\John\Desktop\db\db\db\Setup.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand("INSERT INTO tblpeople (people) VALUES (@ppl)", conn;
string splin = textbox1.Text.Split(' ');
foreach (string pstring in splin)
int rowsAffected = cmd.ExecuteNonQuery();
So any help guys? would be much appreciated.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.