0

I need set 3 parameters in SQLDatasource, binding source to the gridview.
If I remove the parameters, and directly choose datasource from design view, it shows data correctly.
I guess after pass parameters, Oracle has some special way to handle the SQL, but once the parameter passed, gridview got nothing to display. How can I fix this?

See the aspx code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$        ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT d.* FROM DECODATA D where (D.FAMILY like :family) AND (D.SERIES like :series) AND (D.MODEL like :model) ORDER BY D.FAMILY, D.SERIES, D.MODEL">  
         <SelectParameters>  
            <asp:Parameter Name="family" />
            <asp:Parameter Name="series" />
            <asp:Parameter Name="model" />
        </SelectParameters>
    </asp:SqlDataSource>  
The front code is automatically created.  

Code-behind: Search Button: Even I hard code the parameters like that, still not working (This parameters setting works in SQL Server I know)

SqlDataSource1.SelectParameters["family"].DefaultValue = "CLASSIC LOW";
            SqlDataSource1.SelectParameters["series"].DefaultValue = "%";
            SqlDataSource1.SelectParameters["model"].DefaultValue = "%";
            GridView1.DataSource = SqlDataSource1;
            GridView1.DataBind();                 
1
  • That's so strange. I just deleted the gridview control and add a new one, it works. The code works good. Commented Jul 29, 2014 at 16:19

1 Answer 1

0

ok, here is my answer...

 try
        {
            var oraCntStr = new OracleConnectionStringBuilder
            {
                DataSource =
                    "<something to connect to your database>",
                UserID = "<login>",
                Password = "<password>"
            };

            using (OracleConnection oraCntgv = new OracleConnection(oraCntStr.ToString()))
            {
                oraCntgv.Open();
                OracleCommand oraCmd = oraCntgv.CreateCommand();
                oraCmd.Parameters.Add(new OracleParameter("<parameter's name>", OracleDbType.Varchar2));
                oraCmd.Parameters["<parameter's name>"].Value = Unum;
                oraCmd.CommandText = @"<Select sentence with your <:parameter's name>>";
                OracleDataReader oraReader = oraCmd.ExecuteReader();

                if (oraReader.HasRows)
                {
                    GridView1.DataSource = oraReader;
                    GridView1.DataBind();
                }
                oraCmd.Dispose();
                oraReader.Close();
            }

        }
         catch (Exception err)
        {
            tbxTFStr.Text = "Something goes wrong: " + err.Message;
        }

it works for me... this solution uses ODT by Oracle, and don't forget to add

using Oracle.DataAccess.Client;

i used this solution in web-application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.