473,569 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Record not being deleted in dbase, even tho the display on datagrid is deleted..

IN my code behind .vb page for a delete records script (this also does
a deletion confirmation with a javascript popup, this gets called on
my front .aspx page with the datagrid), I'm not sure if he
row.delete() in my Delete_Row sub is correct because when deleting a
record from the dbase, it doesnot get deleted from the actual
database, even tho on the datagrid it does show that the record is
deleted:
'''''''''''''
Imports System.Data
Imports System.Data.Sql Client
Imports System.Configur ation
Imports System.Web.UI.W ebControls
Public Class ConfirmDelDG
Inherits System.Web.UI.P age

Protected WithEvents dtgProducts As
System.Web.UI.W ebControls.Data Grid
Private strConnection As String =
"SERVER=xxxx.xx x.xxx.xx;UID=xx xx;PWD=xxxx;DAT ABASE=players;"
Private strSql As String = "SELECT * FROM pictures Order by pid
desc"
Private objConn As SqlConnection

Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
BindTheGrid()
End If
End Sub

Private Sub BindTheGrid()
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()
End Sub

Private Sub Connect()
If objConn Is Nothing Then
objConn = New SqlConnection(s trConnection)
End If

If objConn.State = ConnectionState .Closed Then
objConn.Open()
End If
End Sub

Private Sub Disconnect()
objConn.Dispose ()
End Sub

Private Sub dtgProducts_Ite mDataBound (ByVal sender As
System.Object, _
ByVal e As DataGridItemEve ntArgs) Handles
dtgProducts.Ite mDataBound

Dim btn As Button
If e.Item.ItemType = ListItemType.It em or e.Item.ItemType =
ListItemType.Al ternatingItem Then
btn = CType(e.Item.Ce lls(0).FindCont rol("btnDelete" ), Button)
btn.Attributes. Add("onclick", "return confirm_delete( );")
End If

End Sub

Public Sub Delete_Row(ByVa l Sender As Object, ByVal E As
DataGridCommand EventArgs)

' Retrieve the ID of the product to be deleted
Dim pid As system.Int32 =
System.Convert. ToInt32(E.Item. Cells(0).Text)

dtgProducts.Edi tItemIndex = -1

' Create and load a DataSet
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

' Mark the product as Deleted in the DataSet
Dim tbl As DataTable = ds.Tables("pict ures")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("pi d") _
}
Dim row As DataRow = tbl.Rows.Find(p id)
row.Delete()
' Display remaining rows in the DataGrid
dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()

End Sub

End Class
''''''''''''

??????
chumley
Jul 21 '05 #1
3 2211
Hey Chumley,

It looks like you're not sending any word of the deletion back to the
database. To the contrary, you're actually re-pulling data from the
database then affecting the delete before letting it refresh the datagrid.

One way to do it would be to pull the data from the database in the
Delete_Row function as you currently do.
- Define a command object that would perform a delete to the effect of
"DELETE * FROM MyTable WHERE PID = @PID"
- Set its parameters
- Set the command object as your data adapter's DeleteCommand.
- Call your data adapter's Update() function.

Just as Fill uses the SelectCommand to pull data through the data adapter to
your data set. The Update will apply the queries referenced in its
InsertCommand, DeleteCommand and UpdateCommand back to the database.

HTH,

John
"Chumley the Walrus" <sp*******@yaho o.com> wrote in message
news:1e******** *************** ***@posting.goo gle.com...
IN my code behind .vb page for a delete records script (this also does
a deletion confirmation with a javascript popup, this gets called on
my front .aspx page with the datagrid), I'm not sure if he
row.delete() in my Delete_Row sub is correct because when deleting a
record from the dbase, it doesnot get deleted from the actual
database, even tho on the datagrid it does show that the record is
deleted:
'''''''''''''
Imports System.Data
Imports System.Data.Sql Client
Imports System.Configur ation
Imports System.Web.UI.W ebControls
Public Class ConfirmDelDG
Inherits System.Web.UI.P age

Protected WithEvents dtgProducts As
System.Web.UI.W ebControls.Data Grid
Private strConnection As String =
"SERVER=xxxx.xx x.xxx.xx;UID=xx xx;PWD=xxxx;DAT ABASE=players;"
Private strSql As String = "SELECT * FROM pictures Order by pid
desc"
Private objConn As SqlConnection

Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
BindTheGrid()
End If
End Sub

Private Sub BindTheGrid()
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()
End Sub

Private Sub Connect()
If objConn Is Nothing Then
objConn = New SqlConnection(s trConnection)
End If

If objConn.State = ConnectionState .Closed Then
objConn.Open()
End If
End Sub

Private Sub Disconnect()
objConn.Dispose ()
End Sub

Private Sub dtgProducts_Ite mDataBound (ByVal sender As
System.Object, _
ByVal e As DataGridItemEve ntArgs) Handles
dtgProducts.Ite mDataBound

Dim btn As Button
If e.Item.ItemType = ListItemType.It em or e.Item.ItemType =
ListItemType.Al ternatingItem Then
btn = CType(e.Item.Ce lls(0).FindCont rol("btnDelete" ), Button)
btn.Attributes. Add("onclick", "return confirm_delete( );")
End If

End Sub

Public Sub Delete_Row(ByVa l Sender As Object, ByVal E As
DataGridCommand EventArgs)

' Retrieve the ID of the product to be deleted
Dim pid As system.Int32 =
System.Convert. ToInt32(E.Item. Cells(0).Text)

dtgProducts.Edi tItemIndex = -1

' Create and load a DataSet
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

' Mark the product as Deleted in the DataSet
Dim tbl As DataTable = ds.Tables("pict ures")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("pi d") _
}
Dim row As DataRow = tbl.Rows.Find(p id)
row.Delete()
' Display remaining rows in the DataGrid
dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()

End Sub

End Class
''''''''''''

??????
chumley

Jul 21 '05 #2
Related comment/question -- In a situation of mine, the data adapter's
update() method didn't do a thing even though everybody I talked to and
everything I read said it would work just fine. Finally I gave up and I had
to resort to using an executenonquery to finally delete the row.

Any thoughts as to why this was the case?

Thanks,
TomG

----------------------------------

"John Spiegel" <js******@YETAN OTHERSPAMHATERc-comld.com> wrote in message
news:eP******** ********@TK2MSF TNGP11.phx.gbl. ..
Hey Chumley,

It looks like you're not sending any word of the deletion back to the
database. To the contrary, you're actually re-pulling data from the
database then affecting the delete before letting it refresh the datagrid.

One way to do it would be to pull the data from the database in the
Delete_Row function as you currently do.
- Define a command object that would perform a delete to the effect of
"DELETE * FROM MyTable WHERE PID = @PID"
- Set its parameters
- Set the command object as your data adapter's DeleteCommand.
- Call your data adapter's Update() function.

Just as Fill uses the SelectCommand to pull data through the data adapter to your data set. The Update will apply the queries referenced in its
InsertCommand, DeleteCommand and UpdateCommand back to the database.

HTH,

John
"Chumley the Walrus" <sp*******@yaho o.com> wrote in message
news:1e******** *************** ***@posting.goo gle.com...
IN my code behind .vb page for a delete records script (this also does
a deletion confirmation with a javascript popup, this gets called on
my front .aspx page with the datagrid), I'm not sure if he
row.delete() in my Delete_Row sub is correct because when deleting a
record from the dbase, it doesnot get deleted from the actual
database, even tho on the datagrid it does show that the record is
deleted:
'''''''''''''
Imports System.Data
Imports System.Data.Sql Client
Imports System.Configur ation
Imports System.Web.UI.W ebControls
Public Class ConfirmDelDG
Inherits System.Web.UI.P age

Protected WithEvents dtgProducts As
System.Web.UI.W ebControls.Data Grid
Private strConnection As String =
"SERVER=xxxx.xx x.xxx.xx;UID=xx xx;PWD=xxxx;DAT ABASE=players;"
Private strSql As String = "SELECT * FROM pictures Order by pid
desc"
Private objConn As SqlConnection

Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
BindTheGrid()
End If
End Sub

Private Sub BindTheGrid()
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()
End Sub

Private Sub Connect()
If objConn Is Nothing Then
objConn = New SqlConnection(s trConnection)
End If

If objConn.State = ConnectionState .Closed Then
objConn.Open()
End If
End Sub

Private Sub Disconnect()
objConn.Dispose ()
End Sub

Private Sub dtgProducts_Ite mDataBound (ByVal sender As
System.Object, _
ByVal e As DataGridItemEve ntArgs) Handles
dtgProducts.Ite mDataBound

Dim btn As Button
If e.Item.ItemType = ListItemType.It em or e.Item.ItemType =
ListItemType.Al ternatingItem Then
btn = CType(e.Item.Ce lls(0).FindCont rol("btnDelete" ), Button)
btn.Attributes. Add("onclick", "return confirm_delete( );")
End If

End Sub

Public Sub Delete_Row(ByVa l Sender As Object, ByVal E As
DataGridCommand EventArgs)

' Retrieve the ID of the product to be deleted
Dim pid As system.Int32 =
System.Convert. ToInt32(E.Item. Cells(0).Text)

dtgProducts.Edi tItemIndex = -1

' Create and load a DataSet
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

' Mark the product as Deleted in the DataSet
Dim tbl As DataTable = ds.Tables("pict ures")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("pi d") _
}
Dim row As DataRow = tbl.Rows.Find(p id)
row.Delete()
' Display remaining rows in the DataGrid
dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()

End Sub

End Class
''''''''''''

??????
chumley


Jul 21 '05 #3
Related comment/question -- In a situation of mine, the data adapter's
update() method didn't do a thing even though everybody I talked to and
everything I read said it would work just fine. Finally I gave up and I had
to resort to using an executenonquery to finally delete the row.

Any thoughts as to why this was the case?

Thanks,
TomG

----------------------------------

"John Spiegel" <js******@YETAN OTHERSPAMHATERc-comld.com> wrote in message
news:eP******** ********@TK2MSF TNGP11.phx.gbl. ..
Hey Chumley,

It looks like you're not sending any word of the deletion back to the
database. To the contrary, you're actually re-pulling data from the
database then affecting the delete before letting it refresh the datagrid.

One way to do it would be to pull the data from the database in the
Delete_Row function as you currently do.
- Define a command object that would perform a delete to the effect of
"DELETE * FROM MyTable WHERE PID = @PID"
- Set its parameters
- Set the command object as your data adapter's DeleteCommand.
- Call your data adapter's Update() function.

Just as Fill uses the SelectCommand to pull data through the data adapter to your data set. The Update will apply the queries referenced in its
InsertCommand, DeleteCommand and UpdateCommand back to the database.

HTH,

John
"Chumley the Walrus" <sp*******@yaho o.com> wrote in message
news:1e******** *************** ***@posting.goo gle.com...
IN my code behind .vb page for a delete records script (this also does
a deletion confirmation with a javascript popup, this gets called on
my front .aspx page with the datagrid), I'm not sure if he
row.delete() in my Delete_Row sub is correct because when deleting a
record from the dbase, it doesnot get deleted from the actual
database, even tho on the datagrid it does show that the record is
deleted:
'''''''''''''
Imports System.Data
Imports System.Data.Sql Client
Imports System.Configur ation
Imports System.Web.UI.W ebControls
Public Class ConfirmDelDG
Inherits System.Web.UI.P age

Protected WithEvents dtgProducts As
System.Web.UI.W ebControls.Data Grid
Private strConnection As String =
"SERVER=xxxx.xx x.xxx.xx;UID=xx xx;PWD=xxxx;DAT ABASE=players;"
Private strSql As String = "SELECT * FROM pictures Order by pid
desc"
Private objConn As SqlConnection

Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
BindTheGrid()
End If
End Sub

Private Sub BindTheGrid()
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()
End Sub

Private Sub Connect()
If objConn Is Nothing Then
objConn = New SqlConnection(s trConnection)
End If

If objConn.State = ConnectionState .Closed Then
objConn.Open()
End If
End Sub

Private Sub Disconnect()
objConn.Dispose ()
End Sub

Private Sub dtgProducts_Ite mDataBound (ByVal sender As
System.Object, _
ByVal e As DataGridItemEve ntArgs) Handles
dtgProducts.Ite mDataBound

Dim btn As Button
If e.Item.ItemType = ListItemType.It em or e.Item.ItemType =
ListItemType.Al ternatingItem Then
btn = CType(e.Item.Ce lls(0).FindCont rol("btnDelete" ), Button)
btn.Attributes. Add("onclick", "return confirm_delete( );")
End If

End Sub

Public Sub Delete_Row(ByVa l Sender As Object, ByVal E As
DataGridCommand EventArgs)

' Retrieve the ID of the product to be deleted
Dim pid As system.Int32 =
System.Convert. ToInt32(E.Item. Cells(0).Text)

dtgProducts.Edi tItemIndex = -1

' Create and load a DataSet
Connect()
Dim adapter As New SqlDataAdapter( strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds , "pictures")
Disconnect()

' Mark the product as Deleted in the DataSet
Dim tbl As DataTable = ds.Tables("pict ures")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("pi d") _
}
Dim row As DataRow = tbl.Rows.Find(p id)
row.Delete()
' Display remaining rows in the DataGrid
dtgProducts.Dat aSource = ds.Tables("pict ures")
dtgProducts.Dat aBind()

End Sub

End Class
''''''''''''

??????
chumley


Jul 21 '05 #4

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

Similar topics

0
1339
by: Symphony | last post by:
Hi,all: our web application using vb.net and xp. we have a web form using a datagrid, when load that page, it will list all our cutomer info. to the datagrid. The first column of the datagrid is "delete button" which bind with CustomerID, when we click delete button the record will be delete properly. But I found that if we us IE refresh...
4
7838
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete event routine shows that AllowDeletions is TRUE. When the Delete button is clicked (without TRACE ON), I get a 'beep', the recordselector (vertical...
0
1845
by: Sharon | last post by:
I have a problem using with dbf file here. I have tried the code below using VB.NET with no errors. However, I use the exact same code in ASP NET, it prompt me error when I tried to insert a record. The error Detail : ERROR Operation must use an updateable query. Description: An unhandled exception occurred during the execution of the
2
286
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if he row.delete() in my Delete_Row sub is correct because when deleting a record from the dbase, it doesnot get deleted from the actual database, even...
3
2284
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data using data in this row before actually remove it from datagrid. I can certainly control with Delete button. But if I want to allow the user to use...
0
1096
by: Iain | last post by:
Hi All I have a datagrid which takes it's data from a table on a remote i-series. This datagrid is loaded on Page Load and the user is able to select a record to edit by pressing the appropriate button. No problem so far. The problem comes in that I appear to have to reload the data into the datagrid before placing it into editstate.
3
2230
by: Ctal | last post by:
I have an app that populates several data tables on load. Each of these are bound to a datagrid. Above each datagrid I have several text boxes that display the data for the active row. There are buttons to allow the user to add, update, and delete a row in the grid. I have an event on cell changed associated with the grid that updates the...
9
2466
by: =?Utf-8?B?UHJhdmlu?= | last post by:
We are using .net Framework 1.1 We are having one page on which we are using this Grid component. From this page we open a popup for adding new record as well as for editing an existing record (For Edit we want to pass the ID of that particular row) And when user clicks on 'SAVE' button in popup window, those changes need to be...
8
1974
by: =?Utf-8?B?bWlrZWc=?= | last post by:
Hi, I am building a small Help Desk application for my company and need to be able to edit "open" help desk issues. I use a simple datagrid to display each issue (6 per page) , with an Edit button. There are a lot of fields across, and my Network Admins would like a way of editing/updating each issue seperately in a a vertical form. I...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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. ...
1
7677
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...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
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...
0
5219
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...
0
3653
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
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

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.