Return to Snippet

Revision: 70443
at February 16, 2016 13:46 by ManuelToledo


Initial Code
Imports System
Imports System.Data
Imports System.Data.SqlClient

'...

Dim constr As String _
	= "User ID=<db_user>;Password=<db_password>;Initial Catalog=<database_name>;Data Source=(local)"


Using con As New SqlConnection(constr)
	Using cmd As New SqlCommand("<stored_procedure_name>")
		cmd.Connection = con
		cmd.CommandType = CommandType.StoredProcedure
		cmd.Parameters.Add("@<param_1>", <value_1>)
		cmd.Parameters.Add("@<param_2>", <value_2>)
		cmd.Parameters.Add("@<param_3>", <value_3>)
		Using sda As New SqlDataAdapter(cmd)
			Dim dt As New DataTable()
			sda.Fill(dt)
			<data_grid_view_component_name>.DataSource = dt
		End Using
	End Using
End Using

Initial URL

                                

Initial Description
Easily populate VB.NET DataGridView with data from MSSQL Server Stored Procedure

Initial Title
Populate VB.NET DataGridView with data from MSSQL Server Stored Procedure

Initial Tags
server

Initial Language
VB.NET