Ramco Ramco

Ramco Ramco

  • 440
  • 3.4k
  • 529.1k

Add Unique Records

Apr 10 2024 3:17 AM

Hi

  I have below code . If already exists it should not be added

string constr = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    string query = "INSERT INTO Category VALUES (@CategoryId,@CategoryName)";
                    using (SqlCommand cmd = new SqlCommand(query))
                    {
                        cmd.Connection = con;
                        cmd.Parameters.AddWithValue("@CategoryId", data.id);
                        cmd.Parameters.AddWithValue("@CategoryName", data.snippet.title);
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                }

Thanks


Answers (4)