0

Hello,

I have a WPF/C# ListBox with one column with several items loaded from an SQL Sever Compact Edition database. I'm trying to delete a selected item from the database, but I'm having difficulties getting the value of the selected item, and because of this it is always returned null and the query although it doesn't fail, doesn't delete anything.

I've created the query using the VS query wizard and it looks like this:


DELETE FROM allBooks
WHERE ([Book Name] = 'book_NameListBox.SelectedItem.ToString()')


The database/connections/queries are not created programatically, they are all added from VS using the available wizards.

Following is the code behind the delete button:

private void Button_Click(object sender, RoutedEventArgs e)
        {
           bTA.DeleteQuery(); // bTA is the TableAdapter
           bTA.Fill(bDS.allBooks); //bDS is the Dataset
        }

I need some help on how to correctly call the value of the Selected Item in the ListBox so that the delete query would work.

thank you.

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by drake10k
0

Try book_NameListBox.Text

the ListBox I'm using is a WPF control. I can not use the .Text method.

0

Try this:
DELETE FROM allBooks
WHERE ([Book Name] = 'book_NameListBox.SelectedItems[0].ToString()')

I've already tried that. The returned value is null.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.