Ok, this should add a new hashtag to the databse if it doesn't already exist, else it should increment the counter.
However, all it does so far is adds new ones, even if they're the same. So I have lots of identical hashtags, all with 1. Any suggestions?
HashTagReader r = new HashTagReader();
int i;
i=1;
if (r.HashTagSearch(s))
MessageBox.Show("I Found it!");
else
{
SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.Table1 (HashTag, Counter) Values (@HashTag,@Counter)", connection);
myCommand.Parameters.Add("@HashTag", SqlDbType.VarChar, 50).Value = s; //Your hashTagvalue
myCommand.Parameters.Add("@Counter", SqlDbType.VarChar, 50).Value = i++; //Your Counter Value
myCommand.ExecuteNonQuery();
}
connection.Close();
The HashTag Search is implemented as such
public bool HashTagSearch(string hashtagstring)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Jordan Moffat\Desktop\coursework\WindowsFormsApplication1\WindowsFormsApplication1\HashTags.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
// SqlConnection connection = new SqlConnection();
// connection.ConnectionString = "C:/Users/Jordan Moffat/Desktop/coursework/WindowsFormsApplication1/WindowsFormsApplication1/HashTags.mdf"; //Your connection string
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "FindString";
command.Parameters.AddWithValue("@MyString", hashtagstring);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
return true;
}
}
catch (Exception)
{
// MessageBox.Show("heel");
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
return false;
}
}