Solved

Deriving a dataset from the data  retrieved via the SQLDatasource control

Posted on 2006-06-28
6
579 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
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

13 Experts available now in Live!

Get 1:1 Help Now