473,804 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Deleting from DataBase

10 New Member
Can anyone explain why this code doesnt delete from the database. Some times it works and some times it errors i am confused.

Expand|Select|Wrap|Line Numbers
  1. Private Sub DeleteBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteBtn.Click
  2.  
  3.     Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
  4.     "Data Source = G2G.mdb"
  5.     Dim oDataTable As New DataTable
  6.     Dim squlStr As String = "SELECT * From Staff"
  7.     Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)
  8.  
  9.         oleDbStaffAdapter.Fill(oDataTable)
  10.         Dim StaffDeleteRow As DataRow
  11.  
  12.         oDataTable.Rows.Item(Val(StaffnoTxt.Text)).Delete()
  13.  
  14.         Dim changes As Integer
  15.         Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
  16.  
  17.         changes = oleDbStaffAdapter.Update(oDataTable)
  18.  
  19.  
  20.     End Sub
Thanks
Dec 7 '07 #1
3 1201
hathan
10 New Member
Hi i am getting An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred in system.data.dll . Some times my code works and some times it doesn't. Its realy wierd. It is erroring on changes = oleDbStaffAdapt er.Update(aData Table) can anyone please help me.

Expand|Select|Wrap|Line Numbers
  1. Private Sub AddBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddBtn.Click
  2.  
  3.     Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
  4.     "Data Source = G2G.mdb"
  5.     Dim aDataTable As New DataTable
  6.     Dim squlStr As String = "SELECT * From Staff"
  7.     Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)
  8.  
  9.  
  10.       Try
  11.             aDataTable.Clear()
  12.             StaffnoTxt.DataBindings.Clear()
  13.             FnameTxt.DataBindings.Clear()
  14.             LastnameTxt.DataBindings.Clear()
  15.             NoTxt.DataBindings.Clear()
  16.             PcodeTxt.DataBindings.Clear()
  17.             DoornoTxt.DataBindings.Clear()
  18.  
  19.             oleDbStaffAdapter.Fill(aDataTable)
  20.             Dim MyNewRow As DataRow = aDataTable.NewRow
  21.  
  22.             MyNewRow("Staff_No") = StaffnoTxt.Text
  23.             MyNewRow("First_Name") = FnameTxt.Text
  24.             MyNewRow("Surname") = LastnameTxt.Text
  25.             MyNewRow("Tel_No") = NoTxt.Text
  26.             MyNewRow("Post_Code") = PcodeTxt.Text
  27.             MyNewRow("House") = DoornoTxt.Text
  28.  
  29.             aDataTable.Rows.Add(MyNewRow)
  30.  
  31.  
  32.             Dim changes As Integer
  33.             Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
  34.             changes = oleDbStaffAdapter.Update(aDataTable)
  35.  
  36.             AddLbl.Text = "New Staff Added"
  37.  
  38.  
  39.         Catch ex As InvalidOperationException
  40.             MsgBox(ex.Message)
  41.         End Try
  42. End Sub
Thanks
Jonathan
Dec 7 '07 #2
kenobewan
4,871 Recognized Expert Specialist
I thought it would have been commandbuilder. Update(aDataTab le), but its late and the screen has become blurred :).
Dec 8 '07 #3
kenobewan
4,871 Recognized Expert Specialist
I note the same code is coming up multiple question and that you are basically multiposting under the guise of different questions. I also find it difficult to believe that this is a university course, although some unis will offer anything if they can find a student.

Your questions appears to be a Homework Assignment and you should make a proper attempt at assignment/program. This question will now be closed and you will have to post a new question when you're ready. I strongly recommend reading the posting guidelines.

MODERATOR
Dec 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1797
by: sparks | last post by:
At first I thought I could just delete the tables and import the tables. BUT my tables have relationships and I can not delete a table with relations. So that only deleted the non relational tables and imported them. Now I am trying to relink the exported tables. this is the code I am using Public Function ReLink() As Boolean On Error Resume Next Dim astrTableNames(1000) As String Dim iintTableNames As Integer
1
8771
by: vadarv | last post by:
Hia! I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control. What I need to is to write to a table in Access, then read these values and then delete records (rows) in Access. By using help functions in WinCC I have this set up: I created an Access database with the WINCC_DATA table and columns (ID, TagValue) with the ID as the Auto Value. ...
5
1498
by: NaziaAkter | last post by:
Hi EveryOne, I am having problem with deleting data form database after anyone have close the site. or any one have click the cancel button after entering data. I know the code for deleting data from a MS Access database, But I don,t know waht code to write in thease cases. Nazia
5
2322
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks for user name, check in the system but does not return the correct answer please help me with it. or if you have better way of doing it would you please mind to tell me.. thanks.. #!/usr/bin/perl -w #use Getopt::Std;
4
2399
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) Context: What I'm essentially trying to do is create a poor man's document imaging system in Access 2007. I have a database that contains forms and modules (but no data) that I'm going to distribute to 200+ users in my company that have limited...
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.