Display (Show) DataSet in View using VB.Net in ASP.Net MVC

on Sep 29, 2021 11:49 PM

Good afternoon,

I want to be able to fill in my html table that is in a .cshtml file in Vb.net.

I have an sql query that returns a dataset to me.

        <td>VALUE 1</td>
        <td>VALUE 2</td>
        <td>VALUE 3</td>
        <td>VALUE 4</td>


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Sep 30, 2021 05:06 AM
on Sep 30, 2021 05:08 AM

Hi luisguillermo...,

Check this example. Now please take its reference and correct your code.


For this example I have used of Northwind database that you can download using the link given below.

Download Northwind Database


Public Class HomeController
    Inherits Controller

    ' GET: Home
    Function Index() As ActionResult
        Return View(GetData())
    End Function

    Private Function GetData() As DataSet
        Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Dim query As String = "SELECT TOP 5 CustomerID,ContactName,Country FROM Customers"
        Using con As SqlConnection = New SqlConnection(conString)
            Dim cmd As SqlCommand = New SqlCommand(query)
            Using sda As SqlDataAdapter = New SqlDataAdapter()
                cmd.Connection = con
                sda.SelectCommand = cmd
                Using ds As DataSet = New DataSet()
                    Return ds
                End Using
            End Using
        End Using
    End Function
End Class


    Layout = Nothing
End Code

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <table cellpadding="0" cellspacing="0">
            @For Each row In Model.Tables(0).Rows