Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 December 22nd, 2005, 06:57 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default deleting row in a datagrid * nightmare :-(

I've been having alot of problems trying to delete row's from my datagrid in asp.net C#. Just can not get it to work and it's driving me mad and really need some help on this. Am new to c# and asp.net as well

My code
Code:
            OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
            myDataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM ["+dtable+"]",objOleDbConn);
            OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);

            DataSet custDS = new DataSet();
            myDataAdapter.Fill(custDS,"+dtable+");

            int rowToDelete = e.Item.ItemIndex;    
                        custDS.Tables["+dtable+"].Rows[rowToDelete].Delete();

            myDataAdapter.Update(custDS,"+dtable+");
            myDataGrid.DataSource=custDS;

            try
            {
                myDataGrid.DataBind();
            }
            catch
            {
                myDataGrid.CurrentPageIndex=0;
                myDataGrid.DataBind();
            }
Getting error's like :

Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.

for

myDataAdapter.Update(custDS,"+dtable+");


Or

Update unable to find TableMapping['Table'] or DataTable 'Table'.

for

myDataAdapter.Update(custDS);


Can some one help help me solve this ?

thanks for ur time and help

 
Old December 22nd, 2005, 08:30 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right i've had a little brake through but got stuck again.

i can get the code below to delete a row if a enter the table name which is stored in the db e.g peopletable

But want be able to delete many different tables rather than one.

tryed to use "dtable" which is a string that gets the name of the table being used and to show the correct datagrid.

But getting an error which am stuck on . any idea's and help would be great thanks for ur time.

Code used to get the table name from a dropdown menu on the poge:

Code:
            if (!(DropDownList1.SelectedIndex == 0)) 
            {
                myDataGrid.Visible = true;

                OleDbDataReader myDataReader;
                OleDbCommand myCommand = new OleDbCommand("Select * From ["+DbId+DropDownList1.SelectedItem.Value+"]", objOleDbConn);


                try 
                {

                    myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    myDataGrid.DataSource = myDataReader;
                    myDataGrid.DataBind();

                //    dtable=DbId+DropDownList1.SelectedItem.Value; 
                    TextBox1.Text=DbId+DropDownList1.SelectedItem.Value; 

                    // creating a dataset
                    OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("SELECT * FROM ["+DbId+DropDownList1.SelectedItem.Value+"]",objOleDbConn);
                    //DataSet TempDataSet = new DataSet();
                    myDataAdapter.Fill(TempDataSet, "dbconn");
                    DataTable TempDataTable = TempDataSet.Tables["["+DbId+DropDownList1.SelectedItem.Value+"]"];
                    OleDbCommandBuilder TempCmdBuilder = new OleDbCommandBuilder(myDataAdapter);               


                    //foreach (DataRow mydataRow in TempDataSet.Tables["dbconn"].Rows)



                } 
                catch (Exception myException) 
                {
                    Response.Write("An error has occurred: " + myException.ToString());
                } 

            } 
            else 
            {
                myDataGrid.Visible = false;
            }

dtable=TextBox1.Text;



the delete code:
Code:
            myDataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM ["+dtable+"]",objOleDbConn);

            OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);

            DataSet custDS = new DataSet();
            myDataAdapter.Fill(custDS,"+dtable+");

            int rowToDelete = e.Item.ItemIndex;    
            //custDS.Tables["2uni"].Rows[rowToDelete].Delete();
            custDS.Tables["+dtable+"].Rows[rowToDelete].Delete();
            myDataAdapter.Update(custDS,"+dtable+");
            myDataGrid.DataSource=custDS;
error

Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.

on

myDataAdapter.Update(custDS,"+dtable+");

thanks for ur time

 
Old December 22nd, 2005, 09:50 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no worries i've solved it :D WAHHHOOOOO . sorry just took me a long time to work out :)


 
Old October 30th, 2006, 04:01 PM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi chrismogz,

iam also experiencing the same problem wen trying to
delete row's from my datagrid in asp.net VB.

Can u plz let me know how u have solved it.

expecting a reply from u.
Bye
 
Old October 30th, 2006, 05:47 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

chrismogz:

One thing that I noticed in this statement:
  myDataAdapter.Fill(TempDataSet, "dbconn"); if I am reading that correctly the second parameter should be a data table instead of a database connection, i.e. dbconn....and I did not see where dbconn was defined as a table....

Hope this helps.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a row of an array Singh591 VB.NET 2002/2003 Basics 1 July 23rd, 2007 04:51 PM
Deleting a row in excel sheet using c# livehed General .NET 1 May 17th, 2006 03:02 PM
problem in deleting the row from datagrid swati_joshi ASP.NET 1.0 and 1.1 Basics 10 March 24th, 2006 11:14 AM
Deleting every other row Russ Thompson Beginning VB 6 1 December 15th, 2004 05:20 AM





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