Hello :D
we've been working on this simple student database where we can add, edit and delete a student record...
sooo going straight to the point I'm having problem with displaying
details from two different tables as you can see we can only open using one connection string and try opening the tables using a INNER JOIN command in SQL as you can see where I fail badly... but there's still a problem with the following namely "dtrStudentContact" which is my other table...
can you please help me with this... thanks In advance :)
private void txtStudentNumber_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string connString = @"//generated by adding databases";
SqlConnection connStudent = new SqlConnection(connString);
connStudent.Open();
//this part is where I fail badly... :(
string sqlSelectStatement = @"select * from student a inner join student contact b on a.studentno=b.studno where a.studno= '" + @txtStudentNumber.Text + "'";
SqlCommand cmdTxt = new SqlCommand(sqlSelectStatement, connStudent);
SqlDataReader dtrStudent = cmdTxt.ExecuteReader();
dtrStudent.Read();
try
{
if ((dtrStudent["Lastname"].ToString().Trim().Length != 0))
{
//ENABLE OTHER CONTROLS
txtLName.Enabled = true;
txtFName.Enabled = true;
txtMI.Enabled = true;
rdoFemale.Enabled = true;
rdoMale.Enabled = true;
cboProgram.Enabled = true;
cboYearLevel.Enabled = true;
btnSave.Enabled = true;
btnDelete.Enabled = true;
}
//FILL UP THOSE OBJECT BY GETTING THE DATA FROM TABLE Student
txtLName.Text = dtrStudent["Lastname"].ToString();
txtFName.Text = dtrStudent["Firstname"].ToString();
txtMI.Text = dtrStudent["MI"].ToString();
txtPERMANENT_ADDRESS = dtrStudentContact["[PERMANENT ADDRESS]"].ToString();
txtMAILING_ADDRESS = dtrStudentContact["[MAILING ADDRESS]"].ToString();
if (dtrStudent["Gender"].ToString().Trim() == "Male")
rdoMale.Checked = true;
if (dtrStudent["Gender"].ToString().Trim() == "Female")
rdoFemale.Checked = true;
cboProgram.Text = dtrStudent["Program"].ToString();
}
catch (Exception ex)
{
MessageBox.Show("No Record Found", "Warning! ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//MessageBox.Show(ex.Message);
}
connStudent.Close();
connStudent.Dispose();
}
}