Solved

dataset connection help

Posted on 2008-10-28
3
225 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

733 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