Skip navigation links

MySQL Forums :: C#, Mono, .Net :: Problem with dynamic DropDownList


Advanced Search

Problem with dynamic DropDownList
Posted by: Chevy Mark Sunderland ()
Date: January 31, 2012 11:26AM

Hi there, I need your appreciated help.

I need populate the dropdownlist #2 with the value selected in the dropdownlist #1.

But I have problem with this query in MySQL:
   SelectCommand="SELECT * FROM tbl_1 WHERE 1 AND _SU LIKE ?"
I need extract with query only first two characters in the string DataValueField.
If DataValueField it's XQ00 I need in the query where XQ.

I try this in the SelectCommand query :
[1]left(?,2)
[2]like '%?%'
[3]like '%'?'%'
[4]like '%' + ? + '%'


But the aspnet page response with error and the dropdownlist #2 not populate.

Quote

SelectCommand="SELECT * FROM tbl_1 WHERE _SU like '%' + ? + '%'"

Server Error in '/' Application.
--------------------------------------------------------------------------------

ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.45-community-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 '+ 'XQ00' + '%'' 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 [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.45-community-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 '+ 'XQ00' + '%'' at line 1

Can u help me?
Thanks in advance.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
    ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
    SelectCommand="SELECT * FROM tbl_1 WHERE 1 LIMIT 0,4"
    DataSourceMode="DataSet">
</asp:SqlDataSource>

<p>dropdownlist #1
<asp:DropDownList ID="DropDownList1" runat="server" Visible="true"
   DataSourceID="SqlDataSource1"
   AutoPostBack="True" 
   DataTextField="_DU" 
   DataValueField="_SU">
<asp:ListItem>SELECT ONE VALUE</asp:ListItem>
</asp:DropDownList>
    </p>


<asp:sqldatasource ID="SqlDataSource2" runat="server"
   ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
   ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
   SelectCommand="SELECT * FROM tbl_1 WHERE 1 AND _SU like ?" 
   DataSourceMode="DataSet">
<selectparameters>
<asp:controlparameter Name="_SZ" ControlID="DropDownList1" PropertyName="SelectedValue" Direction="Input" />
</selectparameters>
</asp:sqldatasource>

<p>dropdownlist #2
<asp:DropDownList ID="DropDownList2" runat="server" Visible="true"
   DataSourceID="SqlDataSource2"
   AutoPostBack="True" 
   DataTextField="_DU"
   DataValueField="_SZ">
</asp:DropDownList>
</p>


Options: ReplyQuote


Subject Written By Posted
Problem with dynamic DropDownList Chevy Mark Sunderland 01/31/2012 11:26AM
Re: Problem with dynamic DropDownList dave lilley 02/03/2012 12:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.