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 February 22nd, 2006, 11:11 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem updating a DataGrid

I have set up a Datagrid, with one column editable. The button BtnWrite_CLick has a click event procedure which is intended to writeh the changes to the Database. But I have a problem getting it to compile.

If I write my procedure as follows:-

Public Sub BtnWrite_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnWrite.Click

        Dim objConnection As OleDb.OleDbConnection
        Dim objCommand As OleDb.OleDbDataAdapter
        Dim objAdapter As OleDb.OleDbDataAdapter
        Dim objBuilder As OleDb.OleDbCommandBuilder

        Dim strConnect As String
        Dim strCommand As String
        Dim strDIP As String


        Dim dgi As DataGridItem
        Dim datedsn As String
        For Each dgi In DgSTDPE.Items


            'DisplayBoundColumnValues(a, e)
            Dim DSNkey As String = e.Item.Cells(0) ' this line is highlighted as an Error
            'Dim a As TableCell = DgSTDPE.Columns.Item
            Try
                datedsn = Request.QueryString("t_dsn")

                StrDemDate = datedsn.Substring(0, 6)
                StrDemNo = datedsn.Substring(7, 4)


                Dim newQty As String = CType(dgi.FindControl("demand_qty"), TextBox).Text

                Dim DataSet2 As New DataSet

                strCommand = "exec dbo.USp_STDPD_Update '" & StrDemDate & "','" & StrDemNo & "','" & newQty & "'"
                objConnection = New OleDb.OleDbConnection(strConn)

                objCommand = New OleDb.OleDbDataAdapter(strCommand, objConnection)
                objCommand.Fill(DataSet2, "due_in")
                Dim objDataView As New DataView(DataSet2.Tables("due_in"))
            Catch ex As Exception
                LblApprepLine.Text = "Datedsn = " & datedsn
            End Try
        Next


    End Sub

the line shown in red is high-lighted by the compiler. If I change the first line to:-

Public Sub BtnWrite_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles BtnWrite.Click

then the bit shown in red gets flagged as an error.

So what do I do?



 
Old February 22nd, 2006, 03:15 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Change This: Dim DSNkey As String = e.Item.Cells(0)

To This: Dim DSNkey As String = e.Item.Cells(0).Text

Your original code it trying to get the cell itself not the text in it.


Jim

 
Old February 28th, 2006, 11:26 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, it's now updating the DataSet and Database correctly.

 
Old February 28th, 2006, 11:42 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad to help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem updating data from a datagrid jazzydonald Visual Basic 2005 Basics 0 October 16th, 2007 06:16 AM
Problem getting updating Database from Datagrid RichardP ASP.NET 1.0 and 1.1 Basics 0 February 17th, 2006 07:55 AM
problem updating using datagrid bananaking ASP.NET 1.0 and 1.1 Basics 7 May 13th, 2005 07:32 AM
problem in updating datagrid noor ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2005 03:10 AM





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