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:
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();
note: I've got the string split because it's only names starting with * to get stored.