Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Going to next page
Message
 
 
À
09/10/2009 13:57:44
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01427461
Message ID:
01428524
Vues:
43
>I've made some progress!!!!!!
>
>I found another "walkthrough" that addressed this issue. Perhaps it's because I'm using a MySql backend, but I needed to use a question mark to set up the parameter. The code which worked is
>< asp:SqlDataSource ID="SqlDataSource1" runat="server" 
>    ConnectionString="< %$ ConnectionStrings:MySqlConnection %>" 
>    ProviderName="< %$ ConnectionStrings:MySqlConnection.ProviderName %>" 
>
>    SelectCommand="SELECT * FROM kpi_excessdeltavalues WHERE customer = ? ">
>    < SelectParameters>
>        < asp:ControlParameter ControlID="txtCustomer" Name="Customer" 
>            PropertyName="Text" Type="String" />
>    < /SelectParameters>
>< /asp:SqlDataSource>
>
>I've changed the WHERE field to point to both character and numeric fields and it worked without having to do any type conversion.
>
>My next step was to try use LIKE in the WHERE clause. Using the wizard got me
> SelectCommand="SELECT * FROM myTable WHERE (myField LIKE '%' + ? + '%')">
>
>I put a 't' in the textbox but got the following error
>ERROR [23000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.18-nt]You have an error in your SQL syntax; check the manual that 
>corresponds to your MySQL server version for the right syntax to use near '+ 't' + '%')' at line 1 
>
>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
>information about the error and where it originated in the code. 
>
>Exception Details: System.Data.Odbc.OdbcException: ERROR [23000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.18-nt]
>You have an error in your SQL syntax; 
>check the manual that corresponds to your MySQL server version for the right syntax to use near '+ 't' + '%')' at line 1
>
>I couldn't find any way to get the % into the SelectCommand without generating an error.
>
>What I wound up doing was putting an invisible textbox on the form and making that the control source for the select statement.
>SelectCommand="SELECT * FROM myTable WHERE (myField LIKE ?)">
>< SelectParameters>
>    < asp:ControlParameter ControlID="txtInvisible" Name="myField" 
>        PropertyName="Text" Type="String" />
>< /SelectParameters>
>
>Protected Sub txtCustomer_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
>    txtInvisible.Text = txtCustomer.Text & "%"
>End Sub
>
>This feels like a kluldge to me. Is there a better way of doing this?
>
>
>Once again, BIG THANKS

You can set your parameter in Selecting event of SQLDataSource. In this case you specify your parameter as Parameter (not a Control Parameter) and set it in Selecting event (which you wire up in ASPX using OnSelecting = "SQLDataSource_Selecting")

See this blog for explanation http://blogs.lessthandot.com/index.php/WebDev/WebDesignGraphicsStyling/setting-sqldatasource-parameter-from-the

BTW, did you try in MySQL directly
select * from MyTable where myField like '%t%'
?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform