Solved

dataset connection help

Posted on 2008-10-28
3
222 Views
Last Modified: 2012-05-05
how do i do so my connection becomes connected to my stored procedure and also dont want db connection to show on page.  example below and code to be tweaked is at the end of page

_________this is the idea______________________________________________

   Dim strConn2 As String = ConfigurationManager.ConnectionStrings("test").ConnectionString
        Dim conn2 As New SqlConnection(strConn2)
 
        conn2.Open()
     
        Dim cmd2 As New Data.SqlClient.SqlCommand("wmItemOptionproductsSp", conn2)
        cmd2.CommandType = CommandType.StoredProcedure

        cmd2.Parameters.AddWithValue("@item", Request.QueryString("option"))

_________________________________________________________________________

______________________this is the dataset that needs to be tweaked ___________

    Dim ad As New SqlDataAdapter("SELECT CategoryName,Description FROM Categories", myConnection)
        Dim ds As New DataSet()
        ad.Fill(ds, "Categories")
0
Comment
Question by:gianitoo
  • 2
3 Comments
 
LVL 16

Expert Comment

by:ororiole
ID: 22827066
I dont understand what it is you are trying to do. Do you want to use the stored procedure to fill the dataset INSTEAD of the current sql command? Or are you trying to add another table to the dataset, where the new table is the result of the stored proc call?
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22830185
trying to connect through stored procedure instead of writing the query on page.  i wrote the example of a connection that i have on top as reference of what i am trying to achieve.  
0
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 22834165
Ok, you dont need to open the connection cause dataAdapter does that for you. But it shouldnt hurt. So you have 90% of it. All you have to do is change this one line :
Dim ad As New SqlDataAdapter("SELECT CategoryName,Description FROM Categories", myConnection)

to the one shown below.

  Dim strConn2 As String = ConfigurationManager.ConnectionStrings("test").ConnectionString
        Dim conn2 As New SqlConnection(strConn2)    
        Dim cmd2 As New Data.SqlClient.SqlCommand("wmItemOptionproductsSp", conn2)
        cmd2.CommandType = CommandType.StoredProcedure
 
        cmd2.Parameters.AddWithValue("@item", Request.QueryString("option"))
 
   Dim ad As New SqlDataAdapter(cmd2)
        Dim ds As New DataSet()
        ad.Fill(ds, "TableName")

Open in new window

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question