Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with deleting items of the database

Newbie
 
Join Date: Jan 2008
Posts: 4
#1: Jan 3 '09
Hi

I have a database(acces) with tabel questions and answers.
-->
tblquestions
questionId -> -> primary key
question -> string


tblanswers
questionId -> primary key
answerId-> primary key
answer-> string

There's a combobox with questions and a listbox with questions of the chosen answer(s).
I have already to add and show the questions, answers.
Now I wan't to delete the answer(s) (in the listbox) of the chosen questions
I have this already


Expand|Select|Wrap|Line Numbers
  1.   con = New OleDbConnection(providerStr & dbLoc)
  2.               con.Open()
  3.            Dim command As New OleDb.OleDbCommand("DELETE FROM Answers WHERE questionId= " & 0 & " AND answer='" & lstAnswers.SelectedIndex.ToString & "')", con)
  4.                command.ExecuteNonQuery()
  5.                con.Close()
pleas help

Member
 
Join Date: Dec 2008
Location: Riverside, CA
Posts: 32
#2: Jan 9 '09

re: Problem with deleting items of the database


If I understood you correctly, you already have the information loaded into the combobox and listbox.

To make use of what is selected in the combobox, either use ComboBox1.SelectedValue or ComboBox1.Text in the SQL query. To use what is selected in the listbox, use the listbox's .SelectedIndex, SelectedText, .SelectedValue, .Text, or whichever you need.

After you have deleted the item from the database, clear the databinding of the list box using ListBox1.DataBindings.Clear(), and set it again like you did originally, or something like this:

Expand|Select|Wrap|Line Numbers
  1. Me.ListBox1.DataBindings.Add(New Binding("Text", DataSet_Of_Answers, "TableName.ColumnName")
Reply

Tags
combobox, listbox