Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 January 5th, 2007, 08:27 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update Problem In DataGrid

Hi Frnds,
    I am trying to edit and update one field of my datagrid. But it is not updating at all.
I am sending my HTML code as well as .VB code. Can you please help me regarding this problem?

Here is my CODE:
======================

Imports System.Data
Imports System.Data.SqlClient


Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents resumedisplay As System.Web.UI.WebControls.DataGrid
    Protected WithEvents editresume As System.Web.UI.WebControls.DataGrid

    Sub BindDataGrid()
        Dim myconn As SqlConnection
        Dim mycmd As SqlDataAdapter
        Dim myds As DataSet

        myconn = New SqlConnection("Server=xyz;user id=sa;password=none;database=myDB")
        myconn.Open()
        mycmd = New SqlDataAdapter("Query1", myconn)
        myds = New DataSet()
        mycmd.Fill(myds, "Query1")
        resumedisplay.DataSource = myds.Tables("Query1").DefaultView
        resumedisplay.DataBind()
        mycmd.Dispose()
        myconn.Close()

    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BindDataGrid()
    End Sub

    Sub EditRecord(ByVal Src As Object, ByVal Args As DataGridCommandEventArgs)
        resumedisplay.EditItemIndex = Args.Item.ItemIndex
        BindDataGrid()
    End Sub

    Sub UpdateRecord(ByVal Src As Object, ByVal Args As DataGridCommandEventArgs)
        Dim sqlConn As SqlConnection
        Dim sqlCmd As SqlCommand
        Dim sqlString, sqlString2 As String
        Dim resumeid As Integer


        resumeid = resumedisplay.DataKeys(Args.Item.ItemIndex)
        Dim custname = CType(Args.Item.Cells(1).Controls(0), TextBox).Text
        sqlString = "Update General_Info SET Name='" & custname & "' WHERE RID='" & resumeid & "'"
        sqlConn = New SqlConnection("Server=xyz;user id=sa;password=none;database=myDB")
        sqlConn.Open()
        sqlString = "Update General_Info SET Name='" & custname & "' WHERE RID='" & resumeid & "' "

        sqlCmd = New SqlCommand(sqlString, sqlConn)
        sqlCmd.ExecuteNonQuery()
        sqlConn.Close()

        resumedisplay.EditItemIndex = -1
        BindDataGrid()
    End Sub

    Sub CancelRecoed(ByVal Src As Object, ByVal Args As DataGridCommandEventArgs)
        resumedisplay.EditItemIndex = -1
        BindDataGrid()
    End Sub


End Class



 
Old January 5th, 2007, 09:09 AM
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

Dont cross post.

http://p2p.wrox.com/topic.asp?TOPIC_ID=54421

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old January 5th, 2007, 09:19 AM
Authorized User
 
Join Date: Jan 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

seems fine to me.Add a label to ur page (Lets say LblMsg)
        Try
              'add the code to update_record here and compile the program
              'if its not showing then there must be an error.Check the text in the label and reply back
              LblMsg.visible=false
        Catch ex As Exception
              LblMsg.visible=true
              LblMsg.text=ex.Message
        End Try


 
Old January 6th, 2007, 06:23 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi RoniR,

          Thanks for your reply. I tried your suggested solution. But I couldn't find any exception. Please help me...I am in big trouble..

Waiting for your response.



 
Old January 6th, 2007, 07:54 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually what happening is, when i'm updating any field (for example-from Prasanta to RoniR) it is not effecting on the variable . I have tested this using one label. Is there any way to resolve this? It will be very helpful if you send me one example(small) code.

 
Old January 6th, 2007, 08:58 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

I think the problem is in this line :
Dim custname = CType(Args.Item.Cells(1).Controls(0), TextBox).Text

Change this line to :
Dim custtextbox as textbox = CType(Args.Item.Cells(1).Controls(0), TextBox)
Dim custname as string = custtextbox.Text

Hope it will solve your problem.
 
Old January 9th, 2007, 06:20 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 Hi Gaurav,

           I tried with your suggested solution. But it did not work. I am totally confused...Can you please send me a small sample code???

Waiting for ur response.

 
Old January 9th, 2007, 07:36 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys...

I have solved my problem.






Similar Threads
Thread Thread Starter Forum Replies Last Post
update records problem in datagrid asad_black ADO.NET 0 September 30th, 2008 01:22 AM
Update Problem In DataGrid prasanta2expert ASP.NET 1.0 and 1.1 Professional 3 January 6th, 2007 03:55 AM
Problem with update database in datagrid annie_stwg ASP.NET 1.0 and 1.1 Basics 4 April 1st, 2006 12:10 AM
Datagrid.update() and DataAdapter.Update aarunlal ASP.NET 2.0 Professional 2 February 23rd, 2006 11:41 PM
Another Chapter 17 problem (DataGrid Update) bolibompa BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 3 May 11th, 2004 12:32 PM





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