After successfully creating a function to work with tags, I encountered an issue where the data is stored in the database as an array instead of a string. How can I resolve this problem?
private tags: string[] = [];
private addTagToProduct($event): void {
this.tags.push($event.target.value);
$event.target.value = "";
}
private deleteTagFromProduct(tag: string): void {
this.tags = this.tags.filter((a) => a !== tag);
}
SERVER
string tags;
public string Tags { get => tags; set => tags = value; }
public Rep CreateProduct(SqlConnection conn, Product products)
{
SqlCommand cmd = conn.CreateCommand();
SqlTransaction transaction;
conn.Open();
transaction = conn.BeginTransaction();
try
{
cmd.CommandText = "INSERT INTO[Products](Tags)" +
" Values (@TagS)";
cmd.Parameters.Clear();
cmd.Parameters.Add("@Tags", SqlDbType.VarChar).Value = Tags;
cmd.Transaction = transaction;
cmd.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
}
finally
{
conn.Close();
}
}