semi working multi search
This commit is contained in:
parent
63402fb1f4
commit
9212fe4650
@ -10,7 +10,7 @@ using System.Collections;
|
|||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
|
||||||
namespace Database2
|
namespace Database3
|
||||||
{
|
{
|
||||||
public class StudentDataTier
|
public class StudentDataTier
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ namespace Database2
|
|||||||
static SqlConnection myConn = new SqlConnection(connString);
|
static SqlConnection myConn = new SqlConnection(connString);
|
||||||
static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand();
|
static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand();
|
||||||
|
|
||||||
public DataSet GetStudents(string studid)
|
public DataSet GetStudents(string studid, string lname, string dob)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -30,9 +30,11 @@ namespace Database2
|
|||||||
cmdString.Connection = myConn;
|
cmdString.Connection = myConn;
|
||||||
cmdString.CommandType = CommandType.StoredProcedure;
|
cmdString.CommandType = CommandType.StoredProcedure;
|
||||||
cmdString.CommandTimeout = 1500;
|
cmdString.CommandTimeout = 1500;
|
||||||
cmdString.CommandText = "GetStudentByID";
|
cmdString.CommandText = "SearchStudent";
|
||||||
// Define input parameter
|
// Define input parameter
|
||||||
cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = studid;
|
cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = studid;
|
||||||
|
cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 25).Value = lname;
|
||||||
|
cmdString.Parameters.Add("@dob", SqlDbType.Date).Value = dob;
|
||||||
// adapter and dataset
|
// adapter and dataset
|
||||||
SqlDataAdapter aAdapter = new SqlDataAdapter();
|
SqlDataAdapter aAdapter = new SqlDataAdapter();
|
||||||
aAdapter.SelectCommand = cmdString;
|
aAdapter.SelectCommand = cmdString;
|
||||||
|
@ -17,7 +17,7 @@ using System.Data;
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using Database2;
|
using Database3;
|
||||||
|
|
||||||
|
|
||||||
namespace Database3
|
namespace Database3
|
||||||
@ -31,23 +31,36 @@ namespace Database3
|
|||||||
|
|
||||||
private void btnSearch_Click(object sender, EventArgs e)
|
private void btnSearch_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string studentid = "";
|
string studentid = "9999999999";
|
||||||
|
string lname = "9999999999";
|
||||||
|
string dob = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DataSet ds = new DataSet();
|
DataSet ds = new DataSet();
|
||||||
StudentDataTier stuDT = new StudentDataTier();
|
StudentDataTier stuDT = new StudentDataTier();
|
||||||
|
|
||||||
studentid = txtStuID.Text.Trim();
|
try
|
||||||
|
{
|
||||||
|
|
||||||
//get the dataset
|
studentid = txtStuID.Text;
|
||||||
ds = stuDT.GetStudents(studentid);
|
lname = txtlname.Text;
|
||||||
|
dob = txtDOB.Text;
|
||||||
|
|
||||||
// check to see if any record is returned
|
}
|
||||||
if (ds.Tables[0].Rows.Count > 0) //there is a record
|
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;
|
dgvStudents.Visible = true;
|
||||||
// get data source
|
// Get data source.
|
||||||
dgvStudents.DataSource = ds.Tables[0];
|
dgvStudents.DataSource = ds.Tables[0];
|
||||||
dgvStudents.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen;
|
dgvStudents.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen;
|
||||||
|
|
||||||
@ -55,12 +68,17 @@ namespace Database3
|
|||||||
dgvStudents.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
|
dgvStudents.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
|
||||||
dgvStudents.ColumnHeadersDefaultCellStyle.BackColor = Color.Green;
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle exception
|
MessageBox.Show($"An error occurred: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user