1

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?

5
  • Try iterating the data over jQuery and create table rows. And finally append the data to the body Commented Jul 5, 2018 at 7:01
  • Whether the request hit on the server side? Commented Jul 5, 2018 at 7:03
  • yes it does while i retrieve i found the result not shown Commented Jul 5, 2018 at 7:04
  • can you switch to razor component, secondly you have tagged your question as using VBA, but it is using vb.net Commented Jul 5, 2018 at 8:12
  • no later i have to convert this to phonegap Commented Jul 5, 2018 at 8:18

1 Answer 1

1

If it's possible to remove the inputs you can do it like this:

    var html = '';      
    $.each(salesDetailData, function (i, item) {

    html += '<tr><td>' + item.ProductName + '</td><td>' + item.Qty + '</td><td>' + item.Price + '</td></tr>';    

   })
  $('tbody').append(html);

your html will look like this:

    <table id="detailTable">
      <thead><tr><th>ProductName</th><th>Qty</th><th>Price</th></tr></thead>
        <tbody>
        </tbody>
    </table>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.