ASP.NET MVC CRUD Example 05 fetch all with SQL Select

preview_player
Показать описание
Part 5 of a web and database application tutorial. In this video we will show how to select all records from a table using the SQL Select statement.
Рекомендации по теме
Комментарии
Автор

You are a gem of a person, thank you!

maxajames
Автор

sir is always required to create a connection string for all files inside controller? or is it depends on the use case?

bernpaul
Автор

Just to help anyone out there who may face problem with getting the connectionString if you are using APSNET Core 3 or above....I'm using ASPNet.Core 6 my connectionString is configured in appsettings.json so I struggled a bit to get the connectionString using the line that says:

private string connectionString = @"connectionString copy and pasted from the db properties" as shown in this video.

That line returned null for me and so my code didn't work but I managed to get around it by creating another function in the model to get the connectionString from appsettings.json instead like this:

public static IConfigurationRoot Configuration;
static class getConnection
{
public static IConfigurationRoot Configuration;

public static string GetConnectionString()
{
var builder = new ConfigurationBuilder()



Configuration = builder.Build();
var connectionString =


return connectionString;

}

}

string connStr =


public List<Model> FetchAll()
{
List<Model> returnList = new List<Model> ();

//access the database
using (SqlConnection connection = new SqlConnection(connStr))
{
//continue the rest of the code from the video
}

}

georgesiafa
welcome to shbcf.ru