Fill datatable through DataAdapter using VB.net and Stored Procedure

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 554
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())


Try

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)
sqlCon.Open()
da.SelectCommand = cmd
da.Fill(dt)
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