Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Going to next page
Message
From
09/10/2009 13:57:44
 
 
To
02/10/2009 19:52:24
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01427461
Message ID:
01428523
Views:
35
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform