Solved

dataset connection help

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now