locked
DropDownList is declared but still get error... RRS feed

  • Question

  • User158340193 posted

    I am still new at .NET coding, but can't see why I'm getting this error when it appears its declared.  Using VB.NET.  Snippets:

    Errs on this line:  strSQLS = "INSERT INTO Schools (MemberID) VALUES ('" & Replace(txtMemberId.Value, "'", "''") & "') "

    Line 58:   strSQLS = "INSERT INTO Schools (MemberID) VALUES ('" & Replace(ddlLabWksBrand.SelectedText.Value, "'", "''") & "') "
    Line 59:   cmdSchProfile = New OleDbCommand(strSQLS, conSchProfile)

    The HTML code for the drop down list box:

          <td><asp:label id="lblWksBrand" Runat="server">Lab Computer Brand:</asp:label></td>
          <td>
           <asp:DropDownList id="ddlLabWksBrand" AutoPostBack="True">
            <asp:ListItem Value="Dell" Selected="True">Dell</asp:ListItem>
            <asp:ListItem Value="Acer">Acer</asp:ListItem>
            <asp:ListItem Value="Compaq">Compaq</asp:ListItem>
            <asp:ListItem Value="e-Machines">e-Machines</asp:ListItem>
            <asp:ListItem Value="Gateway">Gateway</asp:ListItem>
            <asp:ListItem Value="HP">HP</asp:ListItem>
            <asp:ListItem Value="Lenovo">Lenovo</asp:ListItem>
            <asp:ListItem Value="SystemMax">SystemMax</asp:ListItem>
            <asp:ListItem Value="Clone">Clone</asp:ListItem>
            <asp:ListItem Value="Other">Other</asp:ListItem>
           </asp:DropDownList>
          </td>

    Importing...
    <%@ Import Namespace="System"%>
    <%@ Import Namespace="System.Data"%>

    DataReader Example

    ID SchName Conference WkPhone NumITStaff HostEmail LabYN LabWksBrand

    As you can see above, the LabWksBrand is a valid field in the db also.  I've also tried it without using the Replace() function.
    Any help appreciated.

    Wednesday, May 7, 2008 6:39 PM

Answers

  • User1693635062 posted

    There seams to be some odd data in your string "Underlined part":

    Value, "'", "''") &

    I know this is not your problem but in my opinion it could become one.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 8, 2008 2:36 PM
  • User158340193 posted

    xcopyASP,

    Those are from the Replace function, which is used to prevent any single quotes included in text boxes from messing up the SQL statement. And you're right, they aren't needed for this control, so i did remove them.  Same results, so I did what I posted in the previous reply for now.  I'll try something else I guess.  Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 8, 2008 10:38 PM

All replies

  • User1790760290 posted

    Is ddlLabWksBrand.SelectedText.Value correct?

    or it need to change to  ddlLabWksBrand.SelectedItem.Value ?

    Wednesday, May 7, 2008 7:45 PM
  • User158340193 posted

    Thanks. [:)] That will no doubt help with the SQL statement.  However, I get the same error after changing it:

    Compiler Error Message: BC30451: Name 'ddlLabWksBrand' is not declared.
    Line 58:   strSQLS = "INSERT INTO Schools (MemberID) VALUES ('" & Replace(ddlLabWksBrand.SelectedItem.Value, "'", "''") & "') "
     

    Is there a namespace I'm missing perhaps?  I'm importing the following?
    <%@ Import Namespace="System.Web.ui"%>
    <%@ Import Namespace="System"%>
    <%@ Import Namespace="System.Data"%>
    <%@ Import Namespace="System.Data.Odbc"%>
    <%@ Import Namespace="System.Data.Odbc.OdbcCommandBuilder"%>
    <%@ Import Namespace="System.Data.OleDb"%>

    Wednesday, May 7, 2008 7:58 PM
  • User158340193 posted

    As I'm working on this, I'm seeing other strange behavior in the app.  Other dropdownlist boxes are not updating to reflect changes to the attributes, like Selected="True" in the following:

          <td><asp:DropDownList id="ddlHostEmail" runat="server" AutoPostBack="True">
           <asp:ListItem Value="1" Selected="True">--Select Item--</asp:ListItem>
           <asp:ListItem Value="2">Outlook</asp:ListItem>

    In this case, previously I have Outlook set as the item for Value="1".  When I decided to add the --Select Item-- entry to be Value="1" and move Outlook to Value="2", Outlook still shows in the dropdownlist box when the page renders.

    I'll mark yours as the solution Tony and continue tshooting this more.  Thanks.

    Wednesday, May 7, 2008 8:28 PM
  • User1790760290 posted

    Check why ddlLabWksBrand not declared, is your spelling wrong or it inside anotehr server control like gridview?

    Thursday, May 8, 2008 12:01 PM
  • User1693635062 posted

    There seams to be some odd data in your string "Underlined part":

    Value, "'", "''") &

    I know this is not your problem but in my opinion it could become one.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 8, 2008 2:36 PM
  • User158340193 posted

    Thanks.  Yes, I've checked, and as shown in the initial message, all appears correct.  I took it and the code out and other drop down list server controls function correctly, just not that one.  Weird.  I'm continuing to test.

    Thursday, May 8, 2008 10:34 PM
  • User158340193 posted

    xcopyASP,

    Those are from the Replace function, which is used to prevent any single quotes included in text boxes from messing up the SQL statement. And you're right, they aren't needed for this control, so i did remove them.  Same results, so I did what I posted in the previous reply for now.  I'll try something else I guess.  Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 8, 2008 10:38 PM