I am using a class library for my "data layer" and I am trying to create a method to load results from a SP into a datagrid via the .net DataTable.
I am having trouble returning the datatable (dt) object because of error "cannot implicitly convert type datatable to my custom type.
Here are some code snippets:
public DesignationTable GetDesignationTable(string designationName)
{
using (SqlConnection conn = DB.GetSqlConnection())
{
DesignationTable dt = new DataTable();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = @"GET_DESG_DETAILS_BY_ATTRIBUTE";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("DESG_ATTRIBUTE", System.Data.SqlDbType.Text);
p1.Value = designationName;
cmd.Parameters.Add(p1);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dt.Load(dr);
}
return dt;
}
}
public class DesignationTable
{
public string DESG_ATTRIBUTE { get; set; }
public string DESG_ATTRIBUTE_DESC { get; set; }
public string DESG { get; set; }
public string DESG_NAME { get; set; }
public string TYPE { get; set; }
public string TYPE_DESC { get; set; }
public string DESG_PROJECT { get; set; }
public string DESG_PROJECT_DESC { get; set; }
public DateTime START_DATE { get; set; }
public DateTime END_DATE { get; set; }
public string STATUS { get; set; }
public void Load(SqlDataReader dr)
{
DESG_ATTRIBUTE = dr["DESG_ATTRIBUTE"].ToString();
DESG_ATTRIBUTE_DESC = dr["DESG_ATTRIBUTE_DESC"].ToString();
DESG = dr["DESG"].ToString();
DESG_NAME = dr["DESG_NAME"].ToString();
TYPE = dr["TYPE"].ToString();
TYPE_DESC = dr["TYPE_DESC"].ToString();
DESG_PROJECT = dr["DESG_PROJECT"].ToString();
DESG_PROJECT_DESC = dr["DESG_PROJECT__DESC"].ToString();
//START_DATE = DateTime.Parse(reader["START_DATE"].ToString());
//START_DATE = DateTime.Parse(reader["END_DATE"].ToString());
STATUS = dr["STATUS"].ToString();
}
}