58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using EonaCat.Sql;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace Webtester.Pages
|
|
{
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly ILogger<IndexModel> _logger;
|
|
|
|
public IndexModel(ILogger<IndexModel> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public void OnGet()
|
|
{
|
|
TestsqlServer();
|
|
}
|
|
|
|
private static async void TestsqlServer()
|
|
{
|
|
var customerId = "AROUT";
|
|
var result = SqlHelper.ExecuteQuery(
|
|
new Microsoft.Data.SqlClient.SqlConnection(@"Server=localhost;Database=NorthWind;User Id=sa;Password=jeroen;TrustServerCertificate=Yes;"),
|
|
$"SELECT * FROM Customers WHERE CustomerID = @0 AND Country = @1"
|
|
, true, customerId, "UK");
|
|
|
|
if (result.HasResult && result.HasRows)
|
|
{
|
|
Console.WriteLine($"Found '{result.TotalRows}' " + ((result.TotalRows > 1) ? "rows" : "row"));
|
|
Console.WriteLine(string.Empty);
|
|
foreach (var record in result.DataSet)
|
|
{
|
|
Console.WriteLine(record.CustomerID);
|
|
Console.WriteLine(record.ContactTitle);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!result.HasResult)
|
|
{
|
|
Console.WriteLine("No valid result!");
|
|
}
|
|
|
|
if (!result.HasRows)
|
|
{
|
|
Console.WriteLine("No rows found");
|
|
}
|
|
if (result.HasException)
|
|
{
|
|
Console.WriteLine(result.Exception);
|
|
}
|
|
}
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
} |