Download Nuget package Mysql.Data Import namespace MySql.Data.MySqlClient Construct the connectionstring eg., server=localhost;user=root;password=secret;database=myDatabase Employees has three rows EmployeeId, FirstName and LastName var connectionString = $"server={dbCon.Server};user={dbCon.UserName};password={dbCon.Password};database={dbCon.DatabaseName}"; using var connection = new MySqlConnection(connectionString); connection.Open(); string query = "select * from Employees"; var cmd = new MySqlCommand(query, connection); var reader = cmd.ExecuteReader(); while (reader.Read()){ Console.WriteLine($"{reader.GetString(0)} {reader.GetString(1)} {reader.GetString(2)}"); }
Record type Record can be class or struct. Class is default and it need not be defined. public record class Person (string FullName, DateOnly DateOfBirth); equivalent to saying public class Person{ public string FullName {get; init;} = default!; public DateOnly DateOfBirth {get; set;} } public record struct Person(string FullName, DateOnly DateOfBirth); Console.WriteLine(new Person{ FullName = "Kirthiga", DateOfBirth = new DateOnly(1996, 8, 7)}; It will say NameSpace.Person but won't say the details var kirthiga = new Person("Kirthiga", new DateOnly(1996,8,7)); On the other hand when you use record and do a Console.WriteLine(kirthiga); It will print out Person {FullName = "Kirthiga", DateOfBirth = "07/08/1996"} with full details Also when we duplicate classes example, var personA = new Person{ FullName = "Kirthiga", DateOfBirth = "07/08/1996" } var personB = new Person{ FullName = "Kirthiga", DateOfBirth = ...
How to pass command line arguments in Visual Studio 2022? Right-click Projects -> Properties In the window select Debug -> General -> Open debug launch profiles UI How to access the command line variables when top-level statements is used? Console.WriteLine("Hello, World!"); foreach(var s in args) { Console.Write($"{s}, "); } For more information about top-level statements follow this url: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements
Comments
Post a Comment