title: Update if the name exists else insert - in SQL Server
body: <p>I want update in my table if my given filename is already in my database else I want to insert a new row. I try this code but the <code>EXISTS</code> shown error please give me the correct way beacuse iam fresher in SQL </p>
  
  <pre><code>public void SaveData(string filename, string jsonobject)
  {
      SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=;Integrated Security=True");
      SqlCommand cmd;
      SqlCommand cmda;
  
      if EXISTS("SELECT * FROM T_Pages WHERE pagename = '" + filename + "") {
          cmda = new SqlCommand("UPDATE T_Pages SET pagename='" + filename + "',pageinfo='" + jsonobject + "' WHERE pagename='" + filename + "'", con);
          cmda.ExecuteNonQuery();
      }
      else {
          cmd = new SqlCommand("insert into T_Pages (pagename,pageinfo) values('" + filename + "','" + jsonobject + "')", con);
          cmd.ExecuteNonQuery();
      }
  
      con.Close();
  }
  </code></pre>