Reputation: 2381
I have to display some C# code on a page of my web application (ASP.NET MVC application). How can i store C# code (program) in SQL Server ? Consider that i have the following code:
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}
How can i store this code in SQL Server, so that when my application reads the code from the database, the code can be displayed as it is on the page.
Upvotes: 0
Views: 206
Reputation: 3300
Here is a simple SQL Server script demonstrating the concept of storing multi-line string data (such as a code snippet) in a database table:
create table CodeExamples(Id int identity(1,1), Code varchar(max));
insert into CodeExamples(Code) select 'public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}';
select * from CodeExamples;
Upvotes: 1