Posted By

ManuelToledo on 02/16/16


Tagged

mssql stored procedure server VBNet DataGridView


Versions (?)

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


 / Published in: VB.NET
 

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

  1. Imports System
  2. Imports System.Data
  3. Imports System.Data.SqlClient
  4.  
  5. '...
  6.  
  7. Dim constr As String _
  8. = "User ID=<db_user>;Password=<db_password>;Initial Catalog=<database_name>;Data Source=(local)"
  9.  
  10.  
  11. Using con As New SqlConnection(constr)
  12. Using cmd As New SqlCommand("<stored_procedure_name>")
  13. cmd.Connection = con
  14. cmd.CommandType = CommandType.StoredProcedure
  15. cmd.Parameters.Add("@<param_1>", <value_1>)
  16. cmd.Parameters.Add("@<param_2>", <value_2>)
  17. cmd.Parameters.Add("@<param_3>", <value_3>)
  18. Using sda As New SqlDataAdapter(cmd)
  19. Dim dt As New DataTable()
  20. sda.Fill(dt)
  21. <data_grid_view_component_name>.DataSource = dt
  22. End Using
  23. End Using
  24. End Using

Report this snippet  

You need to login to post a comment.