single search functionality

This commit is contained in:
EggMan20339 2024-02-13 14:30:26 -05:00
parent c348c051de
commit 63402fb1f4
6 changed files with 122 additions and 12 deletions

View File

@ -34,6 +34,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Configuration" />
<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>

View File

@ -3,4 +3,8 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<connectionStrings>
<add name="ConnString" connectionString="Data Source=home.eggtech.net;Initial Catalog=college2; connect timeout=30; integrated security=false; User ID=admin;Password=delirium-purveyor-overall-backboned-approval-amino;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

View File

@ -34,6 +34,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Configuration" />
<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>
@ -54,6 +55,7 @@
</Compile>
<Compile Include="Program.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
<Compile Include="StudentDataTier.cs" />
<EmbeddedResource Include="frmSearch.resx">
<DependentUpon>frmSearch.cs</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,61 @@
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;
namespace Database2
{
public class StudentDataTier
{
static String connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
static SqlConnection myConn = new SqlConnection(connString);
static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand();
public DataSet GetStudents(string studid)
{
try
{
// open connection
myConn.Open();
//clear any parameters
cmdString.Parameters.Clear();
// command
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
cmdString.CommandText = "GetStudentByID";
// Define input parameter
cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = studid;
// adapter and dataset
SqlDataAdapter aAdapter = new SqlDataAdapter();
aAdapter.SelectCommand = cmdString;
DataSet aDataSet = new DataSet();
// fill adapter
aAdapter.Fill(aDataSet);
// return dataSet
return aDataSet;
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
}
}

View File

@ -30,14 +30,14 @@
private void InitializeComponent()
{
this.lblDisStID = new System.Windows.Forms.Label();
this.dgvTable = new System.Windows.Forms.DataGridView();
this.dgvStudents = new System.Windows.Forms.DataGridView();
this.lblDislname = new System.Windows.Forms.Label();
this.lblDisDOB = new System.Windows.Forms.Label();
this.txtStuID = new System.Windows.Forms.TextBox();
this.txtlname = new System.Windows.Forms.TextBox();
this.txtDOB = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dgvStudents)).BeginInit();
this.SuspendLayout();
//
// lblDisStID
@ -49,13 +49,13 @@
this.lblDisStID.Text = "Student ID:";
this.lblDisStID.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// dgvTable
// dgvStudents
//
this.dgvTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvTable.Location = new System.Drawing.Point(77, 250);
this.dgvTable.Name = "dgvTable";
this.dgvTable.Size = new System.Drawing.Size(638, 150);
this.dgvTable.TabIndex = 1;
this.dgvStudents.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvStudents.Location = new System.Drawing.Point(77, 250);
this.dgvStudents.Name = "dgvStudents";
this.dgvStudents.Size = new System.Drawing.Size(638, 150);
this.dgvStudents.TabIndex = 1;
//
// lblDislname
//
@ -108,6 +108,7 @@
//
// frmSearch
//
this.AcceptButton = this.btnSearch;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
@ -117,11 +118,11 @@
this.Controls.Add(this.txtStuID);
this.Controls.Add(this.lblDisDOB);
this.Controls.Add(this.lblDislname);
this.Controls.Add(this.dgvTable);
this.Controls.Add(this.dgvStudents);
this.Controls.Add(this.lblDisStID);
this.Name = "frmSearch";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dgvTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dgvStudents)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
@ -134,7 +135,7 @@
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Label lblDisStID;
private System.Windows.Forms.DataGridView dgvTable;
private System.Windows.Forms.DataGridView dgvStudents;
#endregion
}

View File

@ -7,6 +7,18 @@ 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 Database2;
namespace Database3
{
@ -19,7 +31,36 @@ namespace Database3
private void btnSearch_Click(object sender, EventArgs e)
{
string studentid = "";
try
{
DataSet ds = new DataSet();
StudentDataTier stuDT = new StudentDataTier();
studentid = txtStuID.Text.Trim();
//get the dataset
ds = stuDT.GetStudents(studentid);
// 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;
}
}
catch (Exception ex)
{
// Handle exception
}
}
}
}