CNSA-212-Personal/Database3/frmSearch.cs
2024-02-13 15:46:12 -05:00

85 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using Database3;
namespace Database3
{
public partial class frmSearch : Form
{
public frmSearch()
{
InitializeComponent();
}
private void btnSearch_Click(object sender, EventArgs e)
{
string studentid = "9999999999";
string lname = "9999999999";
string dob = null;
try
{
DataSet ds = new DataSet();
StudentDataTier stuDT = new StudentDataTier();
try
{
studentid = txtStuID.Text;
lname = txtlname.Text;
dob = txtDOB.Text;
}
catch (Exception exception)
{
MessageBox.Show("Error Parsing Search Parameters","Error", MessageBoxButtons.OK);
}
// Get the dataset using all three search parameters.
ds = stuDT.GetStudents(studentid, lname, dob);
// Check to see if any record is returned.
if (ds.Tables[0].Rows.Count > 0) // There is a record.
{
dgvStudents.Visible = true;
// Get data source.
dgvStudents.DataSource = ds.Tables[0];
dgvStudents.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen;
// Set the row and column header styles.
dgvStudents.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
dgvStudents.ColumnHeadersDefaultCellStyle.BackColor = Color.Green;
}
else
{
dgvStudents.Visible = false; // Hide the DataGridView if no results are found.
MessageBox.Show("No records found.");
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}");
}
}
}
}