 |
| ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 14th, 2011, 04:09 AM
|
|
Authorized User
|
|
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to delete records in gridview calling a stored procedure
myconnection.ConnectionString = sqlConStr
If myconnection.State <> ConnectionState.Open Then myconnection.Open()
Dim mycommand As SqlCommand
Dim row As GridViewRow = DirectCast(DataGridOdin.Rows(e.RowIndex), GridViewRow)
Dim lbldeleteID As Label = DirectCast(row.FindControl("lblid"), Label)
mycommand = New SqlCommand("sp_ServiceDel", myconnection)
mycommand.CommandType = CommandType.StoredProcedure
'mycommand = New SqlCommand("delete tbl_Service where Service_ID=" + lbldeleteID.Text & "", myconnection)
MsgBox("Do you want to Delete", MsgBoxStyle.OkCancel, "Confirmation")
If (MsgBoxResult.Ok) Then
Dim a As Integer
a = mycommand.ExecuteNonQuery()
MsgBox("Record Deleted")
myconnection.Close()
Bindgrid()
Last edited by priti2010; July 14th, 2011 at 04:16 AM..
|
|

July 14th, 2011, 05:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Ouch....
Quote:
|
mycommand = New SqlCommand("delete tbl_Service where Service_ID=" + lbldeleteID.Text & "", myconnection)
|
In case anyone sees the above post: don't copy this code as is as it's open to SQL injection. If I enter
0 OR 1=1
lin the bldeleteID control, all your records are gone. Ooops.
Also, MsgBox is a Win Forms concept, not an ASP.NET concept and it won't work as intended.
Cheers,
Imar
|
|

July 14th, 2011, 06:23 AM
|
|
Authorized User
|
|
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
not able to delete the particular selected records
Protected Sub DataGridOdin_RowDeleting1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles DataGridOdin.RowDeleting
Try
myconnection.ConnectionString = sqlConStr
If myconnection.State <> ConnectionState.Open Then myconnection.Open()
Dim mycommand As SqlCommand
mycommand = New SqlCommand("sp_ServiceDel", myconnection)
mycommand.CommandType = CommandType.StoredProcedure
mycommand.Parameters.Add("@Service_ID", SqlDbType.Int).Value = e.RowIndex
MsgBox("Do you want to Delete", MsgBoxStyle.OkCancel, "Confirmation")
If (MsgBoxResult.Ok) Then
Dim a As Integer
a = mycommand.ExecuteNonQuery
MsgBox("Record Deleted")
myconnection.Close()
Bindgrid()
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
|
|

July 14th, 2011, 06:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Better, but MsgBox is still a desktop thing, while this forum category and the original post deals with ASP.NET....
Imar
|
|

July 14th, 2011, 06:52 AM
|
|
Authorized User
|
|
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Better, but MsgBox is still a desktop thing, while this forum category and the original post deals with ASP.NET....
Imar
|
even i m working in asp.net but vb as backend and i m new to programming
if i could get some idea about it
|
|

July 14th, 2011, 07:18 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Idea about what? I thought you were answering the original post? Can you elaborate?
Imar
|
|

July 14th, 2011, 07:34 AM
|
|
Authorized User
|
|
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please help
Quote:
Originally Posted by Imar
Idea about what? I thought you were answering the original post? Can you elaborate?
Imar
|
how i can delete or update a select record using stored procedure in gridview
i think my code is not proper so its not working properly
|
|

July 14th, 2011, 07:35 AM
|
|
Authorized User
|
|
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Idea about what? I thought you were answering the original post? Can you elaborate?
Imar
|
do you want to go through my full page so that you can give me an idea
|
|

July 14th, 2011, 07:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
And what is not working? Do you get an error and if so, which one? Also, did you ditch the MsgBox stuff?
How does your stored procedure look? Is it set up to delete an item by its ID? It looks like you're not passing the record's ID, but the relative index in the GridView instead. You may want to query the GridView's DataKeys collection to get the underlying item ID.
Google knows more on this: http://www.google.com/#sclient=psy&h...w=1920&bih=959
If all this doesn't help, please post your relevant code and a clear problem description, or we're not able to help you out much.
Cheers,
Imar
|
|

July 14th, 2011, 07:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
do you want to go through my full page so that you can give me an idea
|
We probably don't want to see the full page, but a trimmed down version showing just the code necessary to explain and / or reproduce the problem.
Cheers,
Imar
|
|
 |