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


/ Published in: VB.NET
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.