This example executes a Stored Procedure when you load a form. This example uses a Data Grid to store the results.

  1. 'Create a SqlCommand to represent the query
    Dim cmd As SqlCommand = SqlConnection1.CreateCommand
    SqlConnection1.CreateCommand()
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = txtQuery.Text

  2. 'Create a SqlDataAdapter to talk to the database
    Dim da As SqlDataAdapter = New SqlDataAdapter
    da.SelectCommand = cmd
  3. 'Create a DataSet to hold the results
    Dim ds As DataSet = New DataSet
    'Fill the Dataset
    da.Fill(ds, "Results")
  4. 'And bind it to the DataGrid
    dgResults.DataSource = ds
    dgResults.DataMember = "Results"
Average rating: