Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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 October 3rd, 2005, 02:57 PM
Authorized User
 
Join Date: Aug 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating a datgrid through an EditColumn command

Hello everyone,

I was hopiung you would be able to help me in updating a Data Grid. Basically I want to have a datagrid with an EditColumn. Once the user edits their row in the Datagrid, they can update the database. I've put together some code for this but I am missing something. Can you please help me find out what it is? I think the error is in this line:

CatagoryParam.Value = e.item.itemindex

thanks,

Ray

Sub DataGrid1_Update(Sender As Object, e As DataGridCommandEventArgs)

    Dim connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\BegASPNet11\mydatabase.mdb"

     Dim dbConnection as New OledbConnection(connectionString) dbConnection.open()

     Dim dbcommandString as String = "INSERT INTO MyCatalogue (Catagory, ProductName) " & _
     "VALUES(@Catagory, @ProductName)"

     Dim dbCommand as new OleDbCommand(dbCommandString, dbConnection)

     Dim CatagoryParam as New OleDbParameter ("@Catagory", OleDbType.VarChar)
         CatagoryParam.Value = e.item.itemindex
         dbCommand.Parameters.Add(CatagoryParam)

        Dim ProductNameParam as New OleDbParameter("@ProductName", OleDbType.VarChar)
         ProductNameParam.Value = e.item.itemindex
         dbCommand.Parameters.Add(ProductNameParam)

     dbCommand.ExecuteNonQuery()
    DataGrid1.DataBind()
     dbConnection.Close()
     End Sub
 
Old October 7th, 2005, 11:22 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You need to specify an index in this line. It referes to the column you want:
Change
CatagoryParam.Value = e.item.itemindex
To
CatagoryParam.Value = e.item.itemindex(some int here)

The index is 0 based, meaning that the first column in the datagrid is 0, NOT 1.

Jim






Similar Threads
Thread Thread Starter Forum Replies Last Post
Command text was not set for the command object Sheraz Khan Classic ASP Databases 2 May 29th, 2007 12:57 AM
Multiple Values Datgrid Javascript MRCS C# 2005 0 October 17th, 2006 09:09 AM
datgrid freeze panes like in excel drachx General .NET 0 July 12th, 2005 01:23 AM
Command text was not set for the command object. deepa12 BOOK: Beginning ASP 3.0 5 November 2nd, 2004 05:37 PM





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