Results 1 to 3 of 3

Thread: ListBox Posting Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262

    ListBox Posting Problem

    I have looked all over and I can not figure this out. I am setting up a form that will allow someone to update a product group category in the database. I want them highlight the item in the listbox and then press a remove button. I can not figure out why this will not work. I have posted the code of the sub below. The code runs fine as long as I dont reference the listbox.

    Any help would be appreciated.

    Code:
    			//We need to mark the selected item as inactive
    			string cmdStr;
    			string connStr;
    
    			cmdStr = "UPDATE productGroup " + 
    					 "SET active = 0 " +
    					 "WHERE Name = '" + lstMain.SelectedItem.Text + "'";
    
    			connStr = System.Configuration.ConfigurationSettings.AppSettings["connSql"];
    
    			// Create connection object
    			SqlConnection  conn = new SqlConnection(connStr);        
    			// Create command object
    			SqlCommand cmd = new SqlCommand(cmdStr, conn);
    
    			try
    			{
    				conn.Open();
    				cmd.ExecuteNonQuery();
    			}
    			catch ( Exception ex )
    			{
    				Response.Write(ex.Message);
    			}
    			finally
    			{
    				conn.Close();
    			}

  2. #2
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276

    Re: ListBox Posting Problem

    Are you getting some error now?

    Otherwise it could be no rows matched the selection. To solve this, try trimming the list box's selected item value.

    Thanks,
    Jemima.
    "Your worst days are never so bad that you are beyond the reach of God's grace...
    and your best days are never so good that you are beyond the need of God's grace."

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262

    Re: ListBox Posting Problem

    If you remove the listbox reference from the sql statement and add anything it works. Its when you reference the listbox does it fail. The sql statement is not failing.

    I get NullException Object not set error on the listbox. Its like, at the point the sub runs, the listbox has been released.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width