Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server parameters C#
    text
    copied!<p>Ok, this should add a new hashtag to the databse if it doesn't already exist, else it should increment the counter.</p> <p>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? </p> <pre><code>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(); </code></pre> <p>The HashTag Search is implemented as such</p> <pre><code>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; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload