I am writing a simple console program for academic purposes. It contains the MSSQL database with one table. Through ADO.NET in it, I do simple CRUD operations. Now I want to do the same, just use .NET Core. The problem occurred with the namespace.
using System.Data.SqlClient; There is also a problem with the connection string:
static string DBaddress = ConfigurationManager.ConnectionStrings["DBConection"].ConnectionString; Accordingly, the code that was written earlier in the standard console application
// Connection handler for all classes; private static bool NonQuery(SqlCommand comm) { int result = -1; using (SqlConnection con = new SqlConnection(DBaddress)) { comm.Connection = con; con.Open(); comm.ExecuteNonQuery(); } return (result == 1)?true:false; } // Read from DB; public static List<Users> ReadDataFromDB() { using (SqlConnection con = new SqlConnection(DBaddress)) { List<Users> users = new List<Users>(); string select = "SELECT * FROM Users"; SqlCommand cmd = new SqlCommand(select, con); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { users.Add(new Users(Convert.ToInt32(reader["Id"]), reader["FirstName"].ToString(), reader["LastName"].ToString())); } } catch { } return users; } } now not working.