Solved

dataset connection help

Posted on 2008-10-28
3
224 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Title # Comments Views Activity
How to create an MVC5, Razor Widget 2 26
VB.NET Textbox input validation 4 37
VS 2015 is giving [No relevant source lines] 2 25
How to repeat the data 4 15
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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