Fill datatable through DataAdapter using and Stored Procedure

Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 229
The below code will do so

Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient

Namespace TestNS
Class Program
Private Shared Sub Main(args As String())


Dim ConnectionPath As String = System.Configuration.ConfigurationManager.ConnectionStrings("DBString").ToString()
Dim da As New SqlDataAdapter()
Dim dt As New DataTable()

Using sqlCon = New SqlConnection(ConnectionPath)
Using cmd As New SqlCommand("SP_Name", sqlCon)
da.SelectCommand = cmd
End Using
End Using
Catch ex As Exception
Throw ex
End Try
End Sub
End Class
End Namespace

First we are creating a connection string which we are passing to a SQL Command Object along with the SP_Name. Then open connection , fetch the record and fill the data table via data adapter

Comments or Responses

Login to post response