public class mCountry
{
public int iCountryID { get; set; }
public string vchCountryName { get; set; }
public Nullable<bool> bActive { get; set; }
public string vchEntryDate { get; set; }
public string vchUpdateDate { get; set; }
}
//Method which will return List of Country type (class)
public static List<Models.mCountry> SelectAllCountries()
{
List<Models.mCountry> lstmstCountry = new List<Models.mCountry>();
DataTable dtCountries = new DataTable();
SqlConnection conn = new SqlConnection(ConnString);
SqlDataAdapter da = new SqlDataAdapter("select * from mstCountries", conn);
try
{
da.Fill(dtCountries);
}
catch
{
return lstmstCountry;
}
//DATATABLE TO LIST CONVERSION
foreach (DataRow dr in dtCountries.Rows)
{
lstmstCountry.Add(new Models.mCountry
{
iCountryID = Convert.ToInt16(dr["iCountryID"]),
vchCountryName = dr["vchCountryName"].ToString(),
bActive = Convert.ToBoolean( dr["bActive"]),
vchEntryDate = dr["vchEntryDate"].ToString(),
vchUpdateDate = dr["vchUpdateDate"].ToString()
});
}
return lstmstCountry;
}
{
public int iCountryID { get; set; }
public string vchCountryName { get; set; }
public Nullable<bool> bActive { get; set; }
public string vchEntryDate { get; set; }
public string vchUpdateDate { get; set; }
}
//Method which will return List of Country type (class)
public static List<Models.mCountry> SelectAllCountries()
{
List<Models.mCountry> lstmstCountry = new List<Models.mCountry>();
DataTable dtCountries = new DataTable();
SqlConnection conn = new SqlConnection(ConnString);
SqlDataAdapter da = new SqlDataAdapter("select * from mstCountries", conn);
try
{
da.Fill(dtCountries);
}
catch
{
return lstmstCountry;
}
//DATATABLE TO LIST CONVERSION
foreach (DataRow dr in dtCountries.Rows)
{
lstmstCountry.Add(new Models.mCountry
{
iCountryID = Convert.ToInt16(dr["iCountryID"]),
vchCountryName = dr["vchCountryName"].ToString(),
bActive = Convert.ToBoolean( dr["bActive"]),
vchEntryDate = dr["vchEntryDate"].ToString(),
vchUpdateDate = dr["vchUpdateDate"].ToString()
});
}
return lstmstCountry;
}
No comments:
Post a Comment