私はこのコードを持っています:
public List<UserTrainingModules> GetTrainingModulesForUser(int userId)
{
List<UserTrainingModules> trainingModules = new List<UserTrainingModules>();
var modules = UserRepository.GetTrainingModulesForUser(userId);
trainingModules.Add(modules); //not correct error is "invalid arguments"
return trainingModules;
}
私のタイプUserTrainingModules:
public class UserTrainingModules
{
public virtual int userTrainingModuleId { get; set; }
public virtual string title { get; set; }
}
私のメソッドGetTrainingModulesForUser:
public List<UserTrainingModules> GetTrainingModulesForUser(int userId)
{
using (SqlConnection conn = new SqlConnection(ZincModelContainer.CONNECTIONSTRING))
{
using (SqlCommand cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "[Zinc].[GetTrainingModulesForUser]";
SqlParameter param = new SqlParameter("@UserId", System.Data.SqlDbType.Int);
param.Value = userId;
cmd.Parameters.Add(param);
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
ICollection<UserTrainingModules> moduleDetail = new List<UserTrainingModules>(); //not sure what i must have here
foreach (DataRow row in dt.Rows)
{
var moduleId = Convert.ToInt32(row["TrainingModuleArtifactScormModules_TrainingModuleArtifactId"]); //this line not correct
var title = row["Title"]; //not correct either
moduleDetail.Add(moduleId,title); //error is no overload method "add" takes 2 arguments
}
return moduleDetail;
}
}
}
}
誰かが私が間違っていることを教えてもらえますか?ありがとう