Hi RivickJoe,
For two tier architecture, create a class library project for database operation and web project to use the class library in it for binding the GridView.
Please refer below sample.
Database
I have made use of the following table Customers with the schema as follows.
I have already inserted few records in the table.
You can download the database table SQL by clicking the download link below.
Download SQL file
HTML
<asp:GridView ID="gvCustomers" runat="server"></asp:GridView>
Class Library
Namespaces
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
Business Logic
public class CustomerBL
{
public DataTable GetData()
{
string conString = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
string query = "SELECT CistomerId Id, Name, Country FROM Customers";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
}
Code
protected void Page_Load(object sender, EventArgs e)
{
CustomerBL customerBL = new CustomerBL();
gvCustomers.DataSource = customerBL.GetData();
gvCustomers.DataBind();
}
Screenshot