Ayush Patil

Ayush Patil

  • 1.5k
  • 178
  • 19.6k

Display Excel data into HTML table in MVC using Oledb

Jun 24 2018 11:04 AM
Here I am trying to get the value into HTML Table using OLEDB Connection. but I am getting the value in table as undefined please give me a solution to show excel data
 
Controller Code:
  1. if (objMotorUnderwritingList.ddlVehicleType == "TW$")  
  2. {  
  3. cmd.Connection = objConn;  
  4. cmd.CommandType = CommandType.Text;  
  5. cmd.CommandText = "SELECT [New upto 3 Yrs],[Above 3 yr to 9 yrs],[Above 9 yrs upto 12 yrs] FROM [" + objMotorUnderwritingList.ddlVehicleType + "] where [ZONE]= '" + objMotorUnderwritingList.ddlZone + "'and [STATE]='" + objMotorUnderwritingList.ddlState + "' and [Category]='" + objMotorUnderwritingList.ddlTWCategory + "'and [Make & Model]='" + objMotorUnderwritingList.ddlTWMakeModel + "'and [Cubic Capacity]='" + objMotorUnderwritingList.ddlTWCC + "' "; oleda = new OleDbDataAdapter(cmd); oleda.Fill(ds, "excelData"); dtResult = ds.Tables["excelData"]; objConn.Close(); var DiscoundList = JsonConvert.SerializeObject(dtResult, Formatting.Indented); return Json(new { jsDiscoundGridList = DiscoundList, }, JsonRequestBehavior.AllowGet);  
  6. }  
Script Code:
  1. success: function (data)  
  2. {  
  3. if (objMotorUnderwritingList.ddlVehicleType == "TW$")  
  4. {  
  5. if (data.jsDiscoundGridList != 0)  
  6. {  
  7. var eachrow = "<tr>" + "<td>" + data.jsDiscoundGridList[0]["New upto 3 Yrs"] + "</td>" + "<td>" + data.jsDiscoundGridList[0]["Above 3 yr to 9 yrs"] + "</td>" + "<td>" + data.jsDiscoundGridList[0]["Above 9 yrs upto 12 yrs"] + "</td>" + "</tr>";  
  8. $('.tbody').html(eachrow); } else { ShowAlert("Something Wrong in TW");  
  9. }  
  10. } 
here I am getting value in DiscoundGridList as
[
{
"New upto 3 Yrs": 40.0,
"Above 3 yr to 9 yrs": 35.0,
"Above 9 yrs upto 12 yrs": 30.0
}
]
 
View/HTML Code:
  1. <div class="col-sm-12" id="divTblTW" style="display: none;"> <div class="tblContainer"> <table class="table table-striped table-bordered " id="tblTW" cellspacing="0" align="center" height="1"> <center><label class="col-sm-12 control-label">Discount % Grid For New (Fresh)/Rolloverst</label></center> <thead> <tr> <th><center>New upto 3 Yrs</center></th> <th><center>Above 3 yr to 9 yrs</center></th> <th><center>Above 9 yrs upto 12 yrs</center></th> </tr> </thead> <tbody class="tbody"></tbody> </table> </div> <br /> <br /> </div>

Answers (1)