472,802 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Help Deleting from DataBase

10
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 1149
hathan
10
Hi i am getting An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll. Some times my code works and some times it doesn't. Its realy wierd. It is erroring on changes = oleDbStaffAdapter.Update(aDataTable) 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 Expert 4TB
I thought it would have been commandbuilder.Update(aDataTable), but its late and the screen has become blurred :).
Dec 8 '07 #3
kenobewan
4,871 Expert 4TB
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
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...
1
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...
5
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...
5
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...
4
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!) ...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.