locked
Get Data from the selection list RRS feed

  • Question

  • User1702362727 posted

    Im using ASP.Net mobile forms..

    I'm currently having a problem with my selectionlist control..

    I used selectionListDate.Selection.Value.ToString(); to get the value of the date when the user clicks the button..

    This one actually works..

    But I also need to use the  Selection.Value.ToString();  to get the customer names..

    The code is selectionListCustomer.Selection.Value.ToString(); but this one returns nothing when I click the button.

    The error is System.NullReferenceException: Object reference not set to an instance of an object.

    Why is this the error eventhough I have already clicked one item from the selection list?

     
    Did I miss something from my code?

    Please help me.. thanks!
     

     

     

    Wednesday, June 4, 2008 10:58 PM

Answers

  • User-207142277 posted

     

    <o:p> </o:p>

    <o:p> </o:p>

    Hi ,

    <o:p> </o:p>

    I can see that everything is fine except the query that ur trying to get “cust code”.

    <o:p> </o:p>

    There something wrong wid the query make sure that the customer name satisfies the

    Where condtion.

    <o:p> </o:p>

      SqlDataAdapter name = new SqlDataAdapter("SELECT CustCode FROM Customers WHERE RTRIM (LastName) + ', '+ RTRIM (FirstName) + ' ' + RTRIM(MI) + '.' =  '"+ customerName +"'", myConnection);

    <o:p> </o:p>

    Rest of ur code is fine...         

    <o:p> </o:p>

    Happy Coding

    <o:p> </o:p>

    Please mark as “Answer” if you find this post helpful

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 5, 2008 7:38 PM

All replies

  • User-207142277 posted

     

    Hi ,

    <o:p> </o:p>

        It will be helpful for us to give proper help if you post all ur code..

    <o:p> </o:p>

    Happy Coding

     

    Thursday, June 5, 2008 2:31 AM
  • User1702362727 posted

     Page1 (this don't work.. doesn't display anything)

     

        myConnection = new SqlConnection(@"Data Source=USER\SQLEXPRESS;"
          + "Initial Catalog=ABC;Integrated Security=True;");

            myConnection.Open();
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;

            int rowPos = 0;

            string customerName = selectionListCustomer.Selection.Value.ToString();

         
            SqlDataAdapter name = new SqlDataAdapter("SELECT CustCode FROM Customers WHERE RTRIM (LastName) + ', '+ RTRIM (FirstName) + ' ' + RTRIM(MI) + '.' =  '"+ customerName +"'", myConnection);
            DataTable dtName = new DataTable();
            name.Fill(dtName);

            Label1.Text = dtName.Rows[rowPos]["CustCode"].ToString();

     

    Page2 (this one works.. displays the date I selected) 

    myConnection = new SqlConnection(@"Data Source=USER\SQLEXPRESS;"
           + "Initial Catalog=ABC;Integrated Security=True;");


            myConnection.Open();
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;

            int rowPos = 0;
           string date = selectionListOrders.Selection.Value.ToString();
            SqlDataAdapter name = new SqlDataAdapter("SELECT Date FROM Orders WHERE Date =' " + date  + " ' ", myConnection);
            DataTable dtName = new DataTable();
            name.Fill(dtName);

            lblDate.Text =  dtName.Rows[rowPos]["Date"].ToString();

     

     

     

     

    The codes from the 2 pages are almost the same.. but the codes in page1 don't work

    Thursday, June 5, 2008 5:29 AM
  • User-207142277 posted

     

    <o:p> </o:p>

    <o:p> </o:p>

    Hi ,

    <o:p> </o:p>

    I can see that everything is fine except the query that ur trying to get “cust code”.

    <o:p> </o:p>

    There something wrong wid the query make sure that the customer name satisfies the

    Where condtion.

    <o:p> </o:p>

      SqlDataAdapter name = new SqlDataAdapter("SELECT CustCode FROM Customers WHERE RTRIM (LastName) + ', '+ RTRIM (FirstName) + ' ' + RTRIM(MI) + '.' =  '"+ customerName +"'", myConnection);

    <o:p> </o:p>

    Rest of ur code is fine...         

    <o:p> </o:p>

    Happy Coding

    <o:p> </o:p>

    Please mark as “Answer” if you find this post helpful

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 5, 2008 7:38 PM