Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
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
 
Old July 14th, 2011, 04:09 AM
Authorized User
 
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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..
 
Old July 14th, 2011, 05:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 14th, 2011, 06:23 AM
Authorized User
 
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old July 14th, 2011, 06:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Better, but MsgBox is still a desktop thing, while this forum category and the original post deals with ASP.NET....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 14th, 2011, 06:52 AM
Authorized User
 
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
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
 
Old July 14th, 2011, 07:18 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Idea about what? I thought you were answering the original post? Can you elaborate?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 14th, 2011, 07:34 AM
Authorized User
 
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help

Quote:
Originally Posted by Imar View Post
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
 
Old July 14th, 2011, 07:35 AM
Authorized User
 
Join Date: Jul 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
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
 
Old July 14th, 2011, 07:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 14th, 2011, 07:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass value to stored procedure? hertendreef SQL Server 2005 3 February 23rd, 2007 11:43 AM
How to pass a parameter to a stored procedure? MaxGay2 VB.NET 2002/2003 Basics 1 November 8th, 2006 02:48 PM
stored procedure with parameters Danmalam VB Databases Basics 0 February 27th, 2005 03:52 PM
How will I pass stored procedure in an asp shoakat SQL Server 2000 1 July 15th, 2004 10:28 PM
SQL Pass though parameters to stored procedures blinton25 SQL Server 2000 3 March 29th, 2004 02:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.