Can anyone explain why this code doesnt delete from the database. Some times it works and some times it errors i am confused. - Private Sub DeleteBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteBtn.Click
-
-
Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source = G2G.mdb"
-
Dim oDataTable As New DataTable
-
Dim squlStr As String = "SELECT * From Staff"
-
Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)
-
-
oleDbStaffAdapter.Fill(oDataTable)
-
Dim StaffDeleteRow As DataRow
-
-
oDataTable.Rows.Item(Val(StaffnoTxt.Text)).Delete()
-
-
Dim changes As Integer
-
Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
-
-
changes = oleDbStaffAdapter.Update(oDataTable)
-
-
-
End Sub
Thanks
3 1172
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. - Private Sub AddBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddBtn.Click
-
-
Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source = G2G.mdb"
-
Dim aDataTable As New DataTable
-
Dim squlStr As String = "SELECT * From Staff"
-
Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)
-
-
-
Try
-
aDataTable.Clear()
-
StaffnoTxt.DataBindings.Clear()
-
FnameTxt.DataBindings.Clear()
-
LastnameTxt.DataBindings.Clear()
-
NoTxt.DataBindings.Clear()
-
PcodeTxt.DataBindings.Clear()
-
DoornoTxt.DataBindings.Clear()
-
-
oleDbStaffAdapter.Fill(aDataTable)
-
Dim MyNewRow As DataRow = aDataTable.NewRow
-
-
MyNewRow("Staff_No") = StaffnoTxt.Text
-
MyNewRow("First_Name") = FnameTxt.Text
-
MyNewRow("Surname") = LastnameTxt.Text
-
MyNewRow("Tel_No") = NoTxt.Text
-
MyNewRow("Post_Code") = PcodeTxt.Text
-
MyNewRow("House") = DoornoTxt.Text
-
-
aDataTable.Rows.Add(MyNewRow)
-
-
-
Dim changes As Integer
-
Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
-
changes = oleDbStaffAdapter.Update(aDataTable)
-
-
AddLbl.Text = "New Staff Added"
-
-
-
Catch ex As InvalidOperationException
-
MsgBox(ex.Message)
-
End Try
-
End Sub
Thanks
Jonathan
I thought it would have been commandbuilder.Update(aDataTable), but its late and the screen has become blurred :).
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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!)
...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |