我有一个四类学生,课程,注册和更新分数
在学生课上:
public class Student
{
public string studID { get; set; }
public string name { get; set; }
public Student() { }
public Student(string StudID,string Name)
{
this.studID = StudID;
this.name = Name;
}
}
在课程中
public class Course
{
public string courseID { get; set; }
public string title { get; set; }
public int credits { get; set; }
public Course()
{
}
public Course(string CourseID, string Name, int Credits)
{
this.courseID = CourseID;
this.title = Name;
this.credits = Credits;
}
}
在注册班
public class Registration
{
public Student studentData { get; set; }
public Course courseData { get; set; }
public DateTime DOEnroll { get; set; }
public Registration ()
{
}
public Registration (Student sData, Course cData, DateTime doe)
{
this.studentData = sData;
this.courseData = cData;
this.DOEnroll = doe;
}
}
在 UpdateScore 类中
public class UpdateScore
{
public Registration enrollData { get; set; }
public int score { get; set; }
public UpdateScore () { }
public UpdateScore (Registration enrData, int sco)
{
this.enrollData = enrData;
this.score = sco;
}
}
现在我正在使用此查询进行更新,但在 studentID 和 CourseID 中显示空数据
代码是:
public static void Update(UpdateScore score)
{
SqlConnection conn = DB.GetConnection();
try
{
conn.Open();
string selectStm = "UPDATE EnrollmentTable set Score = @Score where StudentID = @StudentID AND CourseID = @CourseID";
SqlCommand command = new SqlCommand(selectStm, conn);
SqlParameter param1 = new SqlParameter();
SqlParameter param2 = new SqlParameter();
SqlParameter param3 = new SqlParameter();
param1.ParameterName = "@StudentID";
param2.ParameterName = "@CourseID";
param3.ParameterName = "@Score";
Student st = new Student();
Course cr = new Course();
Registration enr = new Registration ();
enr.courseData = cr;
enr.studentData = st;
score.enrollData = enr;
param1.Value = st.studID ;
param2.Value = cr.courseID;
param3.Value = score.score;
command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);
int i = command.ExecuteNonQuery();
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();//Close Connection
}
}
它给了我这个例外
参数化查询“(@StudentID nvarchar(4000),@CourseID nvarchar(4000),@Score int)U”需要未提供的参数“@StudentID”。
您能告诉我如何获取 StudentID 和 CourseID 中的值吗?