Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #11 (permalink)  
Old July 14th, 2011, 05:09 AM
Authorized User
Points: 63, Level: 1
Points: 63, Level: 1 Points: 63, Level: 1 Points: 63, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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 05:16 AM.
  #12 (permalink)  
Old July 14th, 2011, 06:29 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 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!
  #13 (permalink)  
Old July 14th, 2011, 07:23 AM
Authorized User
Points: 63, Level: 1
Points: 63, Level: 1 Points: 63, Level: 1 Points: 63, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
  #14 (permalink)  
Old July 14th, 2011, 07:45 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 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!
  #15 (permalink)  
Old July 14th, 2011, 07:52 AM
Authorized User
Points: 63, Level: 1
Points: 63, Level: 1 Points: 63, Level: 1 Points: 63, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
  #16 (permalink)  
Old July 14th, 2011, 08:18 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 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!
  #17 (permalink)  
Old July 14th, 2011, 08:34 AM
Authorized User
Points: 63, Level: 1
Points: 63, Level: 1 Points: 63, Level: 1 Points: 63, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
  #18 (permalink)  
Old July 14th, 2011, 08:35 AM
Authorized User
Points: 63, Level: 1
Points: 63, Level: 1 Points: 63, Level: 1 Points: 63, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
  #19 (permalink)  
Old July 14th, 2011, 08:39 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 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!
  #20 (permalink)  
Old July 14th, 2011, 08:41 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 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!
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:28 PM
SQL Pass though parameters to stored procedures blinton25 SQL Server 2000 3 March 29th, 2004 02:49 PM



All times are GMT -4. The time now is 12:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.