Problem with deleting items of the database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pattex007
    New Member
    • Jan 2008
    • 4

    Problem with deleting items of the database

    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


    Code:
      con = New OleDbConnection(providerStr & dbLoc)
                  con.Open()
               Dim command As New OleDb.OleDbCommand("DELETE FROM Answers WHERE questionId= " & 0 & " AND answer='" & lstAnswers.SelectedIndex.ToString & "')", con)
                   command.ExecuteNonQuery()
                   con.Close()
    pleas help
  • Infog
    New Member
    • Dec 2008
    • 36

    #2
    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.Selec tedValue 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.DataBi ndings.Clear(), and set it again like you did originally, or something like this:

    Code:
    Me.ListBox1.DataBindings.Add(New Binding("Text", DataSet_Of_Answers, "TableName.ColumnName")

    Comment

    Working...