I have a function which suppose to receive an object as parameter and use its properties for further use,but when i try to access object properties it mark them as red (can't resolve symbol...) i tried to add few references but it didn't help.
public bool InsertStudent(object student)
{
var db = DAL.Services.SqlServicesPool.HackService;
using (var connection = db.StartConnection())
{
var sqlParam = new SqlParameter[]
{
new SqlParameter("@Name", student.Name),
new SqlParameter("@Lname", student.Lname),
new SqlParameter("@Phone", student.Phone),
new SqlParameter("@Email", student.Email),
new SqlParameter("@Img", student.Img),
new SqlParameter("@CityId", student.CityId)
};
var result = db.Exec(connection, "spInsertNewStudent", sqlParam);
db.StopConnection(connection);
return result;
};
}
The type of student is object
, or more formally System.Object
. This type hasn't any property called Name
or Lname
etc. That's the problem. You should change the type to the class used to create the student object. For instance if you have created the Student object like below:
var student = new Student
{
Name = "foo"
// .....
}
You should change the signature of your method like below:
public bool InsertStudent(Student student)