I am trying to get the SQL table details to HTML table for that, what I've done is I have created a controller and model and view. I also created the SQL table with fields of voucher number and amount. Here is how I created the controller here I have referenced the model, model demo
<HttpGet>
Function GetSalesDetail(invoiceId As String) As JsonResult
Dim listSalesDetail As List(Of Hashtable) = New ModelDemo().GetSalesDetail(invoiceId)
Return Json(listSalesDetail, JsonRequestBehavior.AllowGet)
End Function
the model demo code consists of SQL connection
Public Function GetSalesDetail(invoiceId As String) As List(Of Hashtable)
Dim listSalesDetail As List(Of Hashtable) = New List(Of Hashtable)
Dim arraySalesDetail As Hashtable
'Dim arraySalesDetail As Dictionary(Of String, String) '**Associative array**'
Dim conn = New SqlConnection(connStringLocal)
conn.Open()
Using query = New SqlCommand("SELECT vchNum,productName,Qty,Price,Amount,total FROM BillDetails
WHERE vchNum='" & invoiceId & "'", conn)
Using resultSet = query.ExecuteReader
If resultSet.HasRows Then
While resultSet.Read()
'arraySalesDetail = New Dictionary(Of String, String)
arraySalesDetail = New Hashtable
arraySalesDetail.Add("vchNum", resultSet("vchNum"))
arraySalesDetail.Add("ProductName", resultSet("ProductName"))
arraySalesDetail.Add("Qty", resultSet("Qty"))
arraySalesDetail.Add("Price", resultSet("Price"))
arraySalesDetail.Add("Amount", resultSet("Amount"))
arraySalesDetail.Add("total", resultSet("total"))
listSalesDetail.Add(arraySalesDetail)
End While
End If
resultSet.Close()
'resultSet = Nothing
End Using
End Using
conn.Close()
Return listSalesDetail
End Function
the document.load function consists of
$.get('@Url.Content("~")Home/GetSalesDetail', {
invoiceId: salesHeaderData.invoiceId
})
.done(function(salesDetailData) {
for (var j = 0; j < salesDetailData.length; j++) {
var input = {};
console.log("Loop for list details");
$('input[name="ProductName"]').val(salesDetailData.ProductName);
$('input[name="Qty"').val(salesDetailData.Qty);
$('input[name="Price"').val(salesDetailData.Price);
}
})
and index html consists of
<table id="detailTable">
<thead><tr><th>ProductName</th><th>Qty</th><th>Price</th></tr></thead>
<tbody>
<tr>
<td><input name="ProductName"></td>
<td><input name="Qty"></td>
<td><input name="Price">
</tr>
</tbody>
</table>
and this is how I tried. Can anyone help the load function not working?