473,398 Members | 2,403 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,398 software developers and data experts.

Cant update my database.

I've made a small vb.net program to read my database and delete records
that are specific to my needs. Well, the program says it's complete but
nothing is deleted from my database. I've listed the code below.
Imports System.data.oledb
Imports System.Data

Public Class Form1
Inherits System.Windows.Forms.Form
Public Enum etif
efilename = 0
efilepath = 1
einvoice = 2
ejob = 3
eorder = 4

End Enum

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Friend WithEvents OleDbSelectCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Friend WithEvents DataSet11 As delete_tiff_records.DataSet1
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.DataSet11 = New delete_tiff_records.DataSet1
CType(Me.DataSet11,
System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(40, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(136, 144)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.DeleteCommand = Me.OleDbDeleteCommand1
Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
Me.OleDbDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "tiff", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("filename", "filename"), New
System.Data.Common.DataColumnMapping("filepath", "filepath"), New
System.Data.Common.DataColumnMapping("invoice", "invoice"), New
System.Data.Common.DataColumnMapping("job", "job"), New
System.Data.Common.DataColumnMapping("order", "order")})})
Me.OleDbDataAdapter1.UpdateCommand = Me.OleDbUpdateCommand1
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT filename,
filepath, invoice, job, [order] FROM tiff"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO
tiff(filename, filepath, invoice, job, [order]) VALUES (?, ?, ?, ?, ?"
& _
")"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("filename",
System.Data.OleDb.OleDbType.VarWChar, 50, "filename"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("filepath",
System.Data.OleDb.OleDbType.VarWChar, 50, "filepath"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("invoice",
System.Data.OleDb.OleDbType.Integer, 0, "invoice"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("job",
System.Data.OleDb.OleDbType.VarWChar, 50, "job"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("order",
System.Data.OleDb.OleDbType.Integer, 0, "order"))
'
'OleDbUpdateCommand1
'
Me.OleDbUpdateCommand1.CommandText = "UPDATE tiff SET filename
= ?, filepath = ?, invoice = ?, job = ?, [order] = ? WHE" & _
"RE (filename = ?) AND (filepath = ? OR ? IS NULL AND filepath
IS NULL) AND (invo" & _
"ice = ? OR ? IS NULL AND invoice IS NULL) AND (job = ? OR ? IS
NULL AND job IS N" & _
"ULL) AND ([order] = ? OR ? IS NULL AND [order] IS NULL)"
Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("filename",
System.Data.OleDb.OleDbType.VarWChar, 50, "filename"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("filepath",
System.Data.OleDb.OleDbType.VarWChar, 50, "filepath"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("invoice",
System.Data.OleDb.OleDbType.Integer, 0, "invoice"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("job",
System.Data.OleDb.OleDbType.VarWChar, 50, "job"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("order",
System.Data.OleDb.OleDbType.Integer, 0, "order"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_filenam e",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "filename", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_filepat h",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "filepath", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_filepat h1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "filepath", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_invoice ",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "invoice", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_invoice 1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "invoice", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_job",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "job", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_job1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "job", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_order",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "order", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_order1" ,
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "order", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbDeleteCommand1
'
Me.OleDbDeleteCommand1.CommandText = "DELETE FROM tiff WHERE
(filename = ?) AND (filepath = ? OR ? IS NULL AND filepath" & _
" IS NULL) AND (invoice = ? OR ? IS NULL AND invoice IS NULL)
AND (job = ? OR ? I" & _
"S NULL AND job IS NULL) AND ([order] = ? OR ? IS NULL AND
[order] IS NULL)"
Me.OleDbDeleteCommand1.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_filenam e",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "filename", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_filepat h",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "filepath", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_filepat h1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "filepath", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_invoice ",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "invoice", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_invoice 1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "invoice", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_job",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "job", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_job1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "job", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_order",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "order", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_order1" ,
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "order", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""T:\SCANNING.MDB"";Jet OLEDB:Engine
Type=5;Provider=""Mi" & _
"crosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
OLEDB:SFP=False;persist se" & _
"curity info=False;Extended Properties=;Mode=Share Deny
None;Jet OLEDB:Encrypt Da" & _
"tabase=False;Jet OLEDB:Create System Database=False;Jet
OLEDB:Don't Copy Locale " & _
"on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Je" & _
"t OLEDB:Global Bulk Transactions=1"
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New
System.Globalization.CultureInfo("en-US")
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataSet11,
System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As Long
Dim search As String
Dim dr As DataRow
OleDbDataAdapter1.Fill(DataSet11)
For x = 181363 To 181748
search = "ANLIN-" & x & ".TIF"
For Each dr In DataSet11.tiff
If dr.Item(etif.efilename) = search Then
DataSet11.tiff.Rows.Remove(dr)
Exit For
End If
Next
Next
OleDbDataAdapter1.Update(DataSet11, "tiff")
MessageBox.Show("Done")
End Sub
End Class

Nov 21 '05 #1
5 1534

plenaha...@hotmail.com wrote:
I've made a small vb.net program to read my database and delete records that are specific to my needs. Well, the program says it's complete but nothing is deleted from my database. I've listed the code below.
<snipped>
For x = 181363 To 181748
search = "ANLIN-" & x & ".TIF"
For Each dr In DataSet11.tiff
If dr.Item(etif.efilename) = search Then
DataSet11.tiff.Rows.Remove(dr)
Exit For
End If
Next
Next
OleDbDataAdapter1.Update(DataSet11, "tiff")
MessageBox.Show("Done")
End Sub
End Class

Change this line: DataSet11.tiff.Rows.Remove(dr)

to this instead:
dr.Delete()

This will not remove the records from the DataSet, but it will remove
them from the database when you call OleDbDataAdapter1.Update().

If you want to subsequently remove the rows from the dataset, call
DataSet11.AcceptChanges() immediately after calling the Update()
method.

HTH,
->Alan

Nov 21 '05 #2
Oops. You do not have to call AcceptChanges.

from MSDN: IDataAdapter.Update() method:
http://msdn.microsoft.com/library/de...asp?frame=true

When using Update, the order of execution is as follows:

1. The values in the DataRow are moved to the parameter values.
2. The OnRowUpdating event is raised.
3. The command executes.
4. If the command is set to FirstReturnedRecord, then the first
returned result is placed in the DataRow.
5. If there are output parameters, they are placed in the DataRow.
6. The OnRowUpdated event is raised.
7. AcceptChanges is called.

->AlanM

Nov 21 '05 #3
Now it says
An unhandled exception of type
'System.Data.DeletedRowInaccessibleException' occurred in
system.data.dll

Additional information: Deleted row information cannot be accessed
through the row.

Nov 21 '05 #4
ok, I didn't look at the logic thoroughly.

When you've deleted a row, it's (generally speaking) inaccessible to
you for general usage (as indicated by your exception.

Here's the quick n dirty way to avoid that problem. This is not
terribly optimal, but I'm guessing you just want something that works:

For x = 181363 To 181748
search = "ANLIN-" & x & ".TIF"
For Each dr In DataSet11.tiff
If dr.RowState <> DataRowState.Deleted Then
If dr.Item(etif.efilename) = search Then
DataSet11.tiff.Rows.Remove(dr)
Exit For
End If
End If
Next
Next

I spent a lot of time reading and re-reading all the documentation
inside the System.Data namespace to get to understand this, but I think
Scep's book might be more helpful:
http://www.microsoft.com/mspress/books/5354.asp

->AlanM

Nov 21 '05 #5
Plenham,

You told you deleted datarows however you are removing those.

The difference is that a datarow.delete set the rowstate to "Deleted" with
records which are originaly readed by the dataadapter.fill. Created records
after that will with a datarow.delete be removed when there has not been an
acceptchanges or an update before that time.

When the update for that row is done (and you take the original
dataset,table or row), than all the rows will be removed from the dataset by
the in the update integrated acceptchanges.

http://msdn.microsoft.com/library/de...eleteTopic.asp

Please sent next time only the relative part of your code in your message.
The by the designer created code do most of us know very well.

I hope this helps?

Cor
Nov 21 '05 #6

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

Similar topics

0
by: dd_bdlm | last post by:
I have recently updated my database to include a postcode recognition function. And to perform calculations based on that recognised value. The query that makes all these calculations is very large...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
1
by: Bluebird | last post by:
hi all i am trying to update a record , which is in postgres databse using PHP, it's not showing any error , but records are not updated. summary of the code given below <?php...
1
by: Ilanco | last post by:
I'm new to c#. I am trying to insert or update data to my tables, and in the debug mode everithig looks ok. when i exit and look in the database all the update or insert did not take effect. i'm...
17
by: so many sites so little time | last post by:
all right so the script is pretty simple it goes it retrives what the id of the post is and it lets you edit it well no it doesnt. now if you go to www.kirewire.com/pp2/index/php you will see a...
1
by: mike11d11 | last post by:
I'm doing a simple TableAdapter.Fill filling my datatable from a view within a SQL database. for some reason it is timing out after 30 seconds and I cant seem to find out where in vb.net 2005 I...
4
by: aasif | last post by:
Hi all I have a problem. I update a tablerow, with a new field value, then do accept changes, but when I restart the app the data is the same its not that the old data is copied again to the...
5
by: lazzypink | last post by:
query = "UPDATE Camera SET CameraName=" + CameraName + " WHERE CameraName=" + oldIPCamera.CameraName; hi guys! can help me solve this problem? why i cant update the new camera name (camera_3) for...
6
flexsingh
by: flexsingh | last post by:
Hello there, I have constructed a option of choosing a court only available when member no = "0". This works fine and is in the first code: - <html> <head> </head> <body background="main...
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
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...
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
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...
0
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...

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.