changes
This commit is contained in:
31
DbService.cs
31
DbService.cs
@ -1,14 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MySqlConnector;
|
||||
using de.hottis.genericdatabaseapiservice.Models;
|
||||
|
||||
namespace de.hottis.genericdatabaseapiservice.Services {
|
||||
public interface IDbService {
|
||||
void JustDoSomething(string msg);
|
||||
void JustDoSomething<T>(string msg);
|
||||
|
||||
}
|
||||
|
||||
public class DbService : IDbService {
|
||||
public void JustDoSomething(string msg) {
|
||||
async public void JustDoSomething<T>(string msg) {
|
||||
Console.WriteLine(msg);
|
||||
|
||||
var item = Activator.CreateInstance<T>();
|
||||
|
||||
using (var conn = new MySqlConnection("Server=172.16.10.18;User ID=apiservicetestdb;Password=geheim123;Database=apiservicetestdb")) {
|
||||
await conn.OpenAsync();
|
||||
|
||||
using (var cmd = conn.CreateCommand()) {
|
||||
// cmd.CommandText = "INSERT INTO test1 (txt, nr) VALUES (@txt, @nr)";
|
||||
// cmd.Parameters.AddWithValue("txt", "txt1");
|
||||
// cmd.Parameters.AddWithValue("nr", 12);
|
||||
// await cmd.ExecuteNonQueryAsync();
|
||||
cmd.CommandText = "SELECT id, txt, nr FROM test1";
|
||||
using (var reader = await cmd.ExecuteReaderAsync()) {
|
||||
while (await reader.ReadAsync()) {
|
||||
foreach (var propertyInfo in typeof(T).GetProperties()) {
|
||||
Console.WriteLine(propertyInfo);
|
||||
}
|
||||
Console.WriteLine(reader.GetString("txt"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user