Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deriving a dataset from the data  retrieved via the SQLDatasource control

Posted on 2006-06-28
6
Medium Priority
?
605 Views
Last Modified: 2012-05-05
I have retrieved data from an Oracle database using a SqlDataSource control.  I use it as a datasource for a gridview control.   I also have a 3rd party control that requires a Dataset for binding .  Can I derive a dataset from the data  retrieved via the SQLDatasource control?  Thanks
daforga
0
Comment
Question by:daforga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 2000 total points
ID: 17005083
i thought there would be an easier way, there might be...
but this works - the gridview1 is set to the sqldatasource


        System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(SqlDataSource1.SelectCommand, SqlDataSource1.ConnectionString);
        DataSet ds = new DataSet();

        sda.Fill(ds);

        this.GridView2.DataSource = ds;
        this.GridView2.DataBind();
0
 

Author Comment

by:daforga
ID: 17005541
deanvanrooyen,
Thanks for the timely reply.  
Your approach seems very sound.  However I get an error:
                     ORA-01008: not all variables bound
This is due, I think, to the fact that my origional SQLDatasource command text is parameterized.  I am now wrestling with trying to add that to your proposed formula.  

Here's  the line as I have it :

        Dim da As OracleClient.OracleDataAdapter = New OracleClient.OracleDataAdapter _
                            (SqlDataSource1.SelectCommand, SqlDataSource1.ConnectionString)

In the source of my aspx page, the control parameter is added thusly:
               <SelectParameters >
                    <asp:ControlParameter Name="dept_no" ControlID ="txtSelectDept"  
                            PropertyName="Text" />
                </SelectParameters>
This invisible textbox is filled from an indexchanged event in a grid od company departments.  It drives the query that fills the second grid with specific data.

Any ideas on How to add the input parameter to this mix?

daforga

0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17014623
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17014756
i tried programtically changing the sql datasoruce select paramters and got errors so I tried this rather, bit more work but it works and give the flexibility of changing the sql to whatever you need plus you can add as many parameters as you have @ place holders in the sql. this code should also be safe from sql injection.

        string strcon = SqlDataSource1.ConnectionString;

        System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock FROM [Alphabetical list of products] where supplierid = @id", new System.Data.SqlClient.SqlConnection(strcon));

        sqlCmd.Parameters.Add("@id", SqlDbType.Int ).Value  = GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text;

        System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter();
        sda.SelectCommand = sqlCmd;
        DataSet ds = new DataSet();
        sda.Fill(ds);


        this.GridView2.DataSource = ds;
        this.GridView2.DataBind();


good luck
0
 

Author Comment

by:daforga
ID: 17036873
Thanks so much for the great input.
daforga
0
 

Author Comment

by:daforga
ID: 17036890

This also works in Oracle adapter if you substitute the @ for a :
Thanks
0

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.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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