conquercode
conquercode
CC#
Created by conquercode on 4/21/2023 in #help
❔ Using DataTable in .cshtml File with JavaScript
Hello everyone, I'm still new to using C#, and I'm trying to figure out how you display data from a SQL database that is called in the OnGet() method of my page with a paginated table.
using System.Data;
using System.Data.SqlClient;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebsite.Pages;

public class Responses : PageModel
{
public void OnGet()
{
DataTable table = new DataTable();
const string connectionString = "secret";
using (SqlConnection connection = new SqlConnection(
connectionString )
)
using(SqlCommand cmd = new SqlCommand(
"SELECT * FROM Responses",
connection )
)
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(Dt);
}
}
}
using System.Data;
using System.Data.SqlClient;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebsite.Pages;

public class Responses : PageModel
{
public void OnGet()
{
DataTable table = new DataTable();
const string connectionString = "secret";
using (SqlConnection connection = new SqlConnection(
connectionString )
)
using(SqlCommand cmd = new SqlCommand(
"SELECT * FROM Responses",
connection )
)
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(Dt);
}
}
}
This is where I am so far. Any help is greatly appreciated.
4 replies