1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace SqlServerTest.DataBase {
public class Person { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } }
internal class test_Data_base { public static async void test() { string connectionString = "YourConnectionString";
MDataBase dataBase = new MDataBase(connectionString);
string selectQuery = "SELECT Id, Name, Age FROM People"; SqlParameter[] selectParameters = new SqlParameter[] { }; var dataSet = await dataBase.Select<Person>(selectQuery, selectParameters);
var person1 = new Person { Id = 1, Name = "John", Age = 30 }; var person2 = new Person { Id = 2, Name = "Jane", Age = 25 }; string insertQuery = "INSERT INTO People (Id, Name, Age) VALUES (@Id, @Name, @Age)"; bool insertSuccess = await dataBase.Insert(new List<Person> { person1, person2 }, insertQuery); Console.WriteLine($"Insert success: {insertSuccess}");
var updatePerson = new Person { Id = 1, Name = "John Doe", Age = 32 }; string updateQuery = "UPDATE People SET Name = @Name, Age = @Age WHERE Id = @Id"; bool updateSuccess = await dataBase.Update(updatePerson, updateQuery); Console.WriteLine($"Update success: {updateSuccess}");
var deletePerson = new Person { Id = 2 }; string deleteQuery = "DELETE FROM People WHERE Id = @Id"; bool deleteSuccess = await dataBase.Delete(deletePerson, deleteQuery); Console.WriteLine($"Delete success: {deleteSuccess}");
} } }
|