Hello. I am doing an exercise and faced an problem
my code is:
protected void ddlStudents_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connection);
SqlCommand comm = new SqlCommand("GetFullStudentProfile",conn);
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "GetFullStudentProfile";
SqlDataReader reader;
try
{
conn.Open();
reader = comm.ExecuteReader();
reader.Read();
StringBuilder sb = new StringBuilder();
sb.Append("Name: ");
sb.Append(reader["StudentName"]);
sb.Append(" ");
sb.Append(reader["StudentFamilyName"]);
sb.Append("<br>");
sb.Append("Birthday: ");
sb.Append(reader["Birthday"]);
sb.Append("<br>");
sb.Append("Class: ");
sb.Append(reader["Classname"]);
lbl.Text = sb.ToString();
reader.Close();
}
catch (Exception ex)
{
lbl.Text = ex.Message;
}
finally
{
conn.Close();
}
}
SQL proc
create procedure [dbo].[GetFullStudentProfile2]
as
select StudentID,StudentName,StudentFamilyName,Birthday,cls.Classname
from dbo.Students
where studentId=ddlStudents.SelectedItem.Value
inner join
Classes as cls on cls.ClassId=dbo.Students.StudentId
GO
Problem:
How can I add to my query
ddlStudents.SelectedItemValue
?
Because it shows only the first position from DB.