Student、Course、Registration、UpdateScoreの4つのクラスがあります
StudentClass で:
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;
}
}
In CourseClass
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 に null データが表示されます
コードは次のとおりです。
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 の値を取得する方法を教えてください。