Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 June 4th, 2007, 11:30 PM
Authorized User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to preetham.sarojavenkatesh
Default plz tell me ,how to edit rows in vb.n

can anybody give the code in vb.net for edit,update,delete buttons for datagrid...
                 plz its an urgent...plz

preet
__________________
preet
 
Old June 6th, 2007, 01:13 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Use a button command column and define OnEdit/Update/Delete events and wire your datagrid up to those events. A simple google search on the button command column will help you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 7th, 2007, 11:00 AM
Authorized User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to preetham.sarojavenkatesh
Default

sir,thank for ur response

                                   i did as u said-
but still now also its giving error as::

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



Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 137: Dim id As Integer = Int32.Parse(id_txt.Text)
Line 138: 'Dim Name1 As String = .parse(name_txt.Text)
Line 139: Dim Name1 As String = CType(e.Item.FindControl("name_txt"), Web.UI.WebControls.TextBox).Text
Line 140: 'Dim Name1 As String = CType(e.Item.FindControl("Name"), Web.UI.WebControls.TextBox).Text
Line 141: Dim age1 As Integer = CType(e.Item.FindControl("age_txt"), Web.UI.WebControls.TextBox).Text



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

where the table name is "table1" and fields are "ID","Name","Age","************","Area"

and my textboxes names are "id_txt","name_txt","age_txt","************_txt","area_ txt" respectively....

And i did changes as follows:

Protected Sub datagrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid1.UpdateCommand

If e.CommandName = "Update" Then

Dim id As Integer = Int32.Parse(id_txt.Text)

'Dim Name1 As String = .parse(name_txt.Text)

Dim Name1 As String = CType(e.Item.FindControl("name_txt"), Web.UI.WebControls.TextBox).Text

'Dim Name1 As String = CType(e.Item.FindControl("Name"), Web.UI.WebControls.TextBox).Text

Dim age1 As Integer = CType(e.Item.FindControl("age_txt"), Web.UI.WebControls.TextBox).Text

Dim sex1 As String = CType(e.Item.FindControl("************_txt"), Web.UI.WebControls.TextBox).Text

Dim area1 As String = CType(e.Item.FindControl("area_txt"), Web.UI.WebControls.TextBox).Text

Dim str As String = "UPDATE table1 SET Name='" & Name1 & "', Age = '" & age1 & "',************ = '" & sex1 & "',Area = '" & area1 & " WHERE ID = " & id

'dim str as string = "UPDATE table1 SET name = '" & name & "', description = '" & description & "', price = " & price & " WHERE id = " & id

Dim cn As String = ConfigurationSettings.AppSettings("preeconn")

Dim cmd As New SqlCommand(str, New SqlConnection(cn))

cmd.Connection.Open()

cmd.ExecuteNonQuery()

cmd.Connection.Close()

DataGrid1.EditItemIndex = -1

LoadData()

End If


preet





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net Gridview Column add and edit heading Bryan Stanley ASP.NET 2.0 Basics 2 August 26th, 2007 09:50 PM
plz help( project on friend adder in vb.net) renjininair_2000 VS.NET 2002/2003 0 March 12th, 2006 02:14 AM
Email through vb code Plz give me reply sachinbashetti General .NET 0 September 23rd, 2005 04:27 AM
how to edit/ update records/ rows of csv file vb thePervertedMonk VB How-To 1 December 10th, 2004 02:15 PM





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