• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

Need a good example of using SQLDataAdapter and SPROC's with params

I need to load up a DataSet with multiple tables. I found a good example of how to do this here:

The example on this page loads up the SQLDataAdapters by using a SQL string and calling the SQL directly. My project requirements forbid me from doing that, I need to make any data calls via stored procedures.

What I'm having trouble figuring out is how to load up the SQLDataAdapters from a Sproc, especially considering that the Sproc's take several parameters typically.

Can anyone either write for me, or point me to, a good example of how to do this?
3 Solutions
Here's a small Sample

I am using a Stored Proc by the name MyTest, it takes two parameters, and based on the parameter it selects some record and returns the fields (I am returning only two fields). Then I use this returned rows to fill a DataTable that can easily be added to DataSet

         Dim Cn As SqlConnection = New SqlConnection("YourConnection")
         Dim Cmd As SqlCommand = New SqlCommand("MyTest", Cn)
         Cmd.CommandType = CommandType.StoredProcedure
         Cmd.Parameters.Add(New SqlParameter("RETVALUE", SqlDbType.Int))
         Cmd.Parameters("RETVALUE").Direction = ParameterDirection.ReturnValue
         Cmd.Parameters.Add(New SqlParameter("@P1", SqlDbType.NVarChar, 80, "UserID"))
        Cmd.Parameters.Add(New SqlParameter("@P2", SqlDbType.NVarChar, 40, "Pwd"))
        Cmd.Parameters.Add(New SqlParameter("@O1", SqlDbType.NVarChar, 20))
        Cmd.Parameters.Add(New SqlParameter("@O2", SqlDbType.NVarChar, 80))
        Cmd.Parameters("@O1").Direction = ParameterDirection.Output
        Cmd.Parameters("@O2").Direction = ParameterDirection.Output
        Cmd.Parameters("@P1").Value = "Test"
        Cmd.Parameters("@P2").Value = "Test"
        Dim Dr As SqlDataReader
        Dim Da As New SqlDataAdapter(Cmd)
        Dim DT As New DataTable
        Catch ex As Exception
        End Try

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now