Answer the question
In order to leave comments, you need to log in
How to connect to MS SQL Server in Asp Net Core and see the data?
I've been copy-pasting code that doesn't work for a few days now.
You need to get data from the server table and assign it to an object, array or list.
Without any Entity Framework. Just a Sql query and writing the table to a variable.
Thank you.
Answer the question
In order to leave comments, you need to log in
Include the SqlClient package in the project.json file .
{
"dependencies": {
...//здесь идут ваши зависимости
"System.Data.SqlClient": "4.1.0-*"//это нужно добавить
...
}
}
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("SELECT * FROM dbo.Table", connection))
{
var reader = command.ExecuteReader();
while(reader.Read())
{
var a = reader["Column"];//инициализация значения переменной полем из таблицы БД
}
}
}
connectionString = "Data Source=ServerName;Initial Catalog=DatabaseName;Persist Security Info=True;User ID=UserName;Password=Password;"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question