Junior — Middle
Have you worked with writing SQL queries in your projects?
sobes.tech AI
Answer from AI
Yes, in C# projects, it is common to write SQL queries to interact with the database. This is usually done through ADO.NET, Entity Framework, or Dapper. Here's a simple example of a query using ADO.NET:
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
var command = new SqlCommand("SELECT * FROM Users WHERE Id = @id", connection);
command.Parameters.AddWithValue("@id", userId);
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader["Name"]);
}
}
}
This approach allows for safe and efficient data retrieval from the database.