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 February 9th, 2007, 02:14 AM
Authorized User
Join Date: Aug 2006
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default datagrid update

 please help me to upgrade a row in datagrid using c#.net
i used the code,
public void DataGrid1_Update(object sender,DataGridCommandEventArgs e)
SqlConnection con = new SqlConnection("server=localhost;Persist Security Info=False;User ID=sa;password=sa;Initial Catalog=vms_database;Data Source=server0");
SqlCommand cmd =new SqlCommand ("update Admin_ringtone set songname=@songname,code=@code where id=@id",con);

cmd.Parameters.Add(new SqlParameter("@id",SqlDbType.NChar,10));
cmd.Parameters["@id"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];
cmd.Parameters["@id"].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text;

            cmd.Parameters.Add(new SqlParameter("@songname",SqlDbType.NChar,10));
            cmd.Parameters["@songname"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];
            cmd.Parameters["@songname"].Value = ((TextBox)e.Item.Cells[1].Controls[0]).Text;

            cmd.Parameters.Add(new SqlParameter("@code",SqlDbType.NChar,10));
            cmd.Parameters["@code"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];
            cmd.Parameters["@code"].Value = ((TextBox)e.Item.Cells[2].Controls[0]).Text;


                DataGrid1.EditItemIndex = -1;
                Label1.Text = "Updated";

            catch(SqlException exc)
                Label1.Text = exc.Message;


but it shows an error,Exception Details: System.InvalidCastException: Specified cast is not valid.
it was working perfect previously.now its not working..
please help


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update a datagrid debbiecoates Beginning VB 6 0 January 4th, 2008 05:51 AM
Datagrid.update() and DataAdapter.Update aarunlal ASP.NET 2.0 Professional 2 February 23rd, 2006 11:41 PM
Datagrid Update madhavigujja ASP.NET 1.0 and 1.1 Basics 1 December 18th, 2005 03:10 PM
Datagrid Does Not Update ... wecka .NET Framework 2.0 1 March 28th, 2005 04:46 AM

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