Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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:30 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 .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:08 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

Does this line: Update General_Info SET Name='" & custname & "' WHERE RID='" & resumeid update your database? e.g. does the query hit the table and update the column?

-------------------------
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 6th, 2007, 01:02 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, this line is working fine for my database.


 
Old January 6th, 2007, 03:55 AM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

After you have updated your database, you need to reload the Data after the update, your datagrid still sees the old version of the data.

Refill the dataset then bind to the datagrid.

Have fun,
dynamicsuit

<i>Goin' Mad</i>





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 Basics 7 January 9th, 2007 07:36 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.