sql queries

profilebyorv20n7
974876131.zip

QuireyNeed/~$struction.docx

QuireyNeed/ClassForm.PNG

QuireyNeed/ClassTable.PNG

QuireyNeed/Instruction.docx

Class form:

Teacher should not teaches 2 at the same time.

My code that needs fix

SqlCommand cmd1 = new SqlCommand("select * from ClassInfo WHERE @CTeach IN (TeacherId) AND ( @CTime Not IN (Time) OR @CEndTime Not IN (EndTime)) AND(@CTime NOT IN (Time) And @CEndTime NOT IN(Time)) And (@CTime NOT IN (EndTime) And @CEndTime NOT IN(Time)) ", con);

cmd1.Parameters.AddWithValue("@CTeach", txtTeacherId.Text);

cmd1.Parameters.AddWithValue("@CTime", cmbTime.Text);

cmd1.Parameters.AddWithValue("@CEndTime", cmbEndTime.Text);

SqlDataAdapter DA = new SqlDataAdapter(cmd1);

DA.Fill(Ds);

int i = Ds.Tables[0].Rows.Count;

// to make sure teacher has no class at the same time

if (i > 0)

{

MessageBox.Show("Teacher Has Another Class In This Time ");

Schedule form:

Student Should not take more than one class at the same time. Only student and classes

cmd1 = new SqlCommand("select Schedule.StudentID from Schedule,classinfo,Student WHERE @StudentID NOT IN(Schedule.StudentID) AND @ClassID IN(classinfo.ClassID) OR (STime is Null AND ETime is Not Null)", con);

cmd1.Parameters.AddWithValue("@StudentID", txtStudentID.Text);

cmd1.Parameters.AddWithValue("@ClassID", txtClassID.Text);

DA = new SqlDataAdapter(cmd1);

DA.Fill(Ds3);

int j = Ds3.Tables[0].Rows.Count;

if (j > 0)

{

MessageBox.Show("Student Has Another Class In This Time ");

}

Search button did not work:

It show only first row in the table where it should show all class for one particular student.

cmd1 = new SqlCommand("select Schedule.StudentId, Fname,Lname, Schedule.ClassID, ClassName,STime,ETime from (Schedule JOIN Student ON Student.StudentID = Schedule.StudentId) JOIN ClassInfo ON ClassInfo.ClassID = Schedule.ClassID WHERE @StudentID = Schedule.StudentId", con);

cmd1.Parameters.AddWithValue("@StudentID", txtStudentID.Text);

SqlDataAdapter sqlDataAdap = new SqlDataAdapter(cmd1);

sqlDataAdap.Fill(Ds4);

dataGridView1.DataSource = Ds4.Tables[0];

SqlDataReader reader;

reader = cmd1.ExecuteReader();

while (reader.Read())

{

label3.Text = (reader[0].ToString());

label4.Text = (reader[1].ToString());

label7.Text = (reader[2].ToString());

QuireyNeed/ScheduleForm.PNG

QuireyNeed/ScheduleTable.PNG

QuireyNeed/StudentTable.PNG