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:
- if (objMotorUnderwritingList.ddlVehicleType == "TW$")
- {
- cmd.Connection = objConn;
- cmd.CommandType = CommandType.Text;
- 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);
- }
Script Code:
- success: function (data)
- {
- if (objMotorUnderwritingList.ddlVehicleType == "TW$")
- {
- if (data.jsDiscoundGridList != 0)
- {
- 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>";
- $('.tbody').html(eachrow); } else { ShowAlert("Something Wrong in TW");
- }
- }
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:
- <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>