private static List Read()
{
using (var cOnnect= new SqlConnection(connectionString))
{
connect.Open();
var query = connect.Query("SELECT TOP 1000 [Id],[Name],[Grade] FROM [TESTDB].[dbo].[Student];");
return query.ToList();
}
}
private static void Add()
{
using (var cOnnect= new SqlConnection(connectionString))
{
connect.Open();
var result = connect.Execute("INSERT INTO [dbo].[Student]([Id],[Name],[Grade])VALUES(@Id,@Name,@Grade);", new[] {
new { Id=2,Name="李四",Grade=1},
new { Id=3,Name="王五",Grade=1},
new { Id=4,Name="赵六",Grade=1}
});
Console.WriteLine("影响行数{0}", result);
}
}
private static void Update()
{
using (var cOnnect= new SqlConnection(connectionString))
{
connect.Open();
var result = connect.Execute("UPDATE [dbo].[Student] SET [Grade] = @Grade WHERE Id=@Id; ", new { Id = 2, Grade = 2 });
Console.WriteLine("影响行数{0}", result);
}
}
private static void Delete()
{
using (var cOnnect= new SqlConnection(connectionString))
{
connect.Open();
var result = connect.Execute("DELETE FROM [dbo].[Student] WHERE Id =@Id; ", new { Id = 1 });
Console.WriteLine("影响行数{0}", result);
}
}