1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- namespace MySQLTool;
- public class MySqlTest
- {
- public void Test()
- {
- // 执行查询
- var queryResult = MySQLHelper.ExecuteQuery("SELECT * FROM your_table");
- foreach (var row in queryResult)
- {
- foreach (var pair in row)
- {
- Console.WriteLine($"{pair.Key}: {pair.Value}");
- }
- Console.WriteLine("-----------");
- }
- User user = new User { Name = "John Doe", Email = "john@example.com" };
- int rowsInserted = MySQLHelper.Insert("users", user);
- Console.WriteLine($"Rows inserted: {rowsInserted}");
- // 更新记录示例
- string updateCondition = "Name = 'John Doe'";
- User updatedUser = new User { Email = "new_email@example.com" };
- int rowsUpdated = MySQLHelper.Update("users", updatedUser, updateCondition);
- Console.WriteLine($"Rows updated: {rowsUpdated}");
- // 删除记录示例
- string deleteCondition = "Name = 'John Doe'";
- int rowsDeleted = MySQLHelper.Delete("users", deleteCondition);
- Console.WriteLine($"Rows deleted: {rowsDeleted}");
- // 执行反序列化操作示例
- var customObjectList = MySQLHelper.Query<User>("users");
- foreach (var item in customObjectList)
- {
- Console.WriteLine($"Name: {item.Name}, Email: {item.Email}");
- }
- }
-
- public class User
- {
- public string Name { get; set; }
- public string Email { get; set; }
- }
- }
|