Json format from angular
books:"tables",
Color:[
Color:red,
Color:white
]
DataModel.cs
public string Books{get;set;}
Public string Colors{get;set;}
How to store in database table like separated by commas in same row of column using C# code
output:Colors
Red,White
Prasad RaveendranPosted Sep 16, 2023, 12:04 PM
To store data separated by commas in the same row of a database column using C#, you can follow these steps:
Create a model class to represent your data:
Deserialize the JSON data from Angular into an instance of the DataModel class:
Concatenate the Color values with commas and store it in the database. Assuming you are using Entity Framework, here's an example of how you can do it:
In this example, replace YourDbContext with your actual Entity Framework database context class, and YourEntity with the name of the entity you want to save the data in.
This code will deserialize the JSON data, concatenate the Color values with commas, and store them in the Colors column of your database table.
Ali BenchaabanPosted Sep 16, 2023, 11:23 AM