הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Tuesday, September 18, 2012 5:43 AM
can you please help me with this error... i tried to delete a row i a listview but it gots an error... thanks a lot ... or any code that you can suggest to me ... by the way vb.net and excel only no database used..
thanks
Private
Sub Ddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ddelete.Click
If DeleteValidate1() = True Then
Return
End If
'=================================================================='The number of seleted record(s) in the listview...
If MsgBox("There is no undo once data is deleted...." _
& vbNewLine &
"Are you sure you want to delete this " & "(" & Me.LvDepartments.SelectedItems.Count & ")" & " selected record(s)?", _
MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, "Confirmation...") = MsgBoxResult.Yes Then
For Each ListViewSelected As ListViewItem In Me.LvDepartments.SelectedItems 'For Each Seleted...
ListViewSelected.Remove()
Call OpenConnection1()
With OleDapter
.DeleteCommand =
New OleDb.OleDbCommand()
.DeleteCommand.CommandText =
"DELETE FROM [Department$] WHERE ([DepartmentCode] = @DepartmentCode)"
.DeleteCommand.Connection = OleCon
.DeleteCommand.Parameters.Add(
"@DepartmentCode", OleDb.OleDbType.VarWChar, 50, "DepartmentCode").Value = ListViewSelected.Text.ToString()
.DeleteCommand.ExecuteNonQuery()
End With
Call CloseConnection1()
Next
MsgBox(
"Record(s) deleted...", MsgBoxStyle.Information, "Record(s) deleted...")
Call OpenConnection1()
Call Initialized1()
Call PopulateListview1()
Call CloseConnection1()
Else
MsgBox(
"Canceled...", MsgBoxStyle.Information, "Canceled...")
Call OpenConnection1()
Call Initialized1()
Call PopulateListView1()
Call CloseConnection1()
End If
End Sub
All replies (3)
Tuesday, September 18, 2012 5:51 AM ✅Answered
You should read the following Article http://support.microsoft.com/kb/257819
Delete
You are more restricted in deleting Excel data than data from a relational data source. In a relational database, "row" has no meaning or existence apart from "record"; in an Excel worksheet, this is not true. You can delete values in fields (cells). However, you cannot:
-
- Delete an entire record at once or you receive the following error message: Deleting data in a linked table is not supported by this ISAM. You can only delete a record by blanking out the contents of each individual field.
- Delete the value in a cell containing an Excel formula or you receive the following error message: Operation is not allowed in this context.
- You cannot delete the empty spreadsheet row(s) in which the deleted data was located, and your recordset will continue to display empty records corresponding to these empty rows.
You've taught me everything I know but not everything you know.
Tuesday, September 18, 2012 5:46 AM
Than put this in the header of your question, then those who know of that will look at it, now everybody looks at it and because of that you get no replies.
by the way vb.net and excel
Success
Cor
Tuesday, September 18, 2012 1:23 PM
As Mr. Monkeyboy correctly pointed out, the Excel data access driver cannot delete rows. You would have to use Excel automation to do this.
Paul ~~~~ Microsoft MVP (Visual Basic)