473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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


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
Jan 3 '09 #1
1 1107
Infog
36
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")
Jan 9 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Matthew Wells | last post by:
I'm using this code to delete all relationships in my mdb file iFlag = 1 Do While iFlag <> 0 iFlag = 0 For Each rel In db.Relations db.Relations.Delete rel.Name iFlag = 1 Next rel Loop
3
by: jm | last post by:
I have a simple query. It has two tables. If I open the tables separately, I can add records. If I open them up together, the recordset is not updateable. As best I know, this has never been a...
0
by: Earl Anderson | last post by:
I copied a Household Inventory database template in A97 (WinXP) and modified it for use in my office. Modifications consisted of changing some table names, deleting some fields, adding some fields...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
10
by: A_PK | last post by:
I am writing mobile application using Vb.net when i click the last row of list view, and try to delete it.... will promtpy the following message "Additional information:...
0
by: steven.shannon | last post by:
Hello, I'm writing an app that involves deleting all the items in a specified Outlook folder regardless of item type (i.e. Contacts, Tasks, etc.). This code was ported from VBA where it worked...
5
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last...
8
by: Christian Bruckhoff | last post by:
Hi. I got a problem with deleting items of a vector. I did it like this: void THIS::bashDelPerson() { cout << "Bitte Suchstring eingeben: "; char search; cin >search;...
2
by: Brad Pears | last post by:
I am working on a new vb.net 2005 project using SQL server 2000 as the backend db. I have a listview where control I want a user to be able to select either just one or multiple rows in the...
1
by: Kyosuke18 | last post by:
Hi everyone, I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(80040e14)': Syntax error in string in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.