From 9155095a3e404766f2ea3c3c1628b99e91c463f2 Mon Sep 17 00:00:00 2001 From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:16:03 -0500 Subject: [PATCH] added double clikc and population to the edit form --- Database3/StudentDataTier.cs | 37 +++++++++++++++++++++++++++++++++ Database3/frmEdit.Designer.cs | 1 + Database3/frmEdit.cs | 34 +++++++++++++++++++++++++++++- Database3/frmSearch.Designer.cs | 10 ++++----- Database3/frmSearch.cs | 2 +- 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/Database3/StudentDataTier.cs b/Database3/StudentDataTier.cs index 0441c17..7a58fc6 100644 --- a/Database3/StudentDataTier.cs +++ b/Database3/StudentDataTier.cs @@ -56,7 +56,44 @@ namespace Database3 } } + + public DataSet GetStudents(string StuID) + { + + + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "GetByStudentIDS"; + // Define input parameter + cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = StuID; + // 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(); + } + } } diff --git a/Database3/frmEdit.Designer.cs b/Database3/frmEdit.Designer.cs index 42fecc1..008b820 100644 --- a/Database3/frmEdit.Designer.cs +++ b/Database3/frmEdit.Designer.cs @@ -214,6 +214,7 @@ namespace Database3 this.Controls.Add(this.lblDisStuID); this.Name = "frmEdit"; this.Text = "frmEdit"; + this.Load += new System.EventHandler(this.frmEdit_Load); this.ResumeLayout(false); this.PerformLayout(); } diff --git a/Database3/frmEdit.cs b/Database3/frmEdit.cs index 565574c..c8c7d36 100644 --- a/Database3/frmEdit.cs +++ b/Database3/frmEdit.cs @@ -1,4 +1,6 @@ -using System.Windows.Forms; +using System; +using System.Data; +using System.Windows.Forms; namespace Database3 { @@ -8,5 +10,35 @@ namespace Database3 { InitializeComponent(); } + + private void frmEdit_Load(object sender, EventArgs e) + { + // txtStuID.Text = frmSearch.myID; + + try + { + + + DataSet ds = new DataSet(); + StudentDataTier stuDT = new StudentDataTier(); + + ds = stuDT.GetStudents(frmSearch.myID.ToString()); + + if (ds.Tables[0].Rows.Count > 0) + { + + txtStuID.Text = ds.Tables[0].Rows[0]["student_id"].ToString(); + txtStuID.Enabled = false; + txtfname.Text = ds.Tables[0].Rows[0]["fname"].ToString(); + txtlname.Text = ds.Tables[0].Rows[0]["lname"].ToString(); + + } + } + catch (Exception exception) + { + // Do Nothing + } + + } } } \ No newline at end of file diff --git a/Database3/frmSearch.Designer.cs b/Database3/frmSearch.Designer.cs index fdb86ab..20a2175 100644 --- a/Database3/frmSearch.Designer.cs +++ b/Database3/frmSearch.Designer.cs @@ -70,31 +70,31 @@ // this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripSeparator1, this.cmuSearch, this.cmuEdit, this.cmuDelete }); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(110, 76); + this.contextMenuStrip1.Size = new System.Drawing.Size(153, 98); // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(106, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(149, 6); // // cmuSearch // this.cmuSearch.Name = "cmuSearch"; - this.cmuSearch.Size = new System.Drawing.Size(109, 22); + this.cmuSearch.Size = new System.Drawing.Size(152, 22); this.cmuSearch.Text = "Search"; this.cmuSearch.Click += new System.EventHandler(this.cmuSearch_Click); // // cmuEdit // this.cmuEdit.Name = "cmuEdit"; - this.cmuEdit.Size = new System.Drawing.Size(109, 22); + this.cmuEdit.Size = new System.Drawing.Size(152, 22); this.cmuEdit.Text = "Edit"; this.cmuEdit.Click += new System.EventHandler(this.cmuEdit_Click); // // cmuDelete // this.cmuDelete.Name = "cmuDelete"; - this.cmuDelete.Size = new System.Drawing.Size(109, 22); + this.cmuDelete.Size = new System.Drawing.Size(152, 22); this.cmuDelete.Text = "Delete"; // // lblDislname diff --git a/Database3/frmSearch.cs b/Database3/frmSearch.cs index c56a5d7..4650c1a 100644 --- a/Database3/frmSearch.cs +++ b/Database3/frmSearch.cs @@ -116,7 +116,7 @@ namespace Database3 private void cmuEdit_Click(object sender, EventArgs e) { - + dgvStudents_DoubleClick(sender, e); } }