hi I use datatable to bind data into table below are codes:
Getting error object reference not set to an instance of an object.
public DataTable PopulateReseller()
{
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "SELECT * FROM Resellers";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
}
}
}
return dt;
}
public ActionResult List()
{
var model = new SearchViewModel();
model.Ostans = PopulateOstan();
model.Reseller = PopulateReseller();
return View(model);
}
View Model:
public class SearchViewModel
{
public Reseller Reseller2 { get; set; }
public IEnumerable Reseller1 { get; set; }
public DataTable Reseller { get; set; }
public List Ostans { get; set; }
public List Citeies { get; set; }
}