Can't remove a row in dataset that is Gridview's datasource

I have the gridview display records and I add a check box in gridview, then I let user choose the row that they want to remove when they hit Remove button. The code when in VB NET form worked but I transfer it into C# and it does not work no more. Please advise. Following is the code. Prolem is at the btnDelete_Click event line 78:


78                   myDS.Tables("Catalog").Rows(row.RowIndex).Delete();
It says "Error	1	Non-invocable member 'System.Data.DataSet.Tables' cannot be used like a method."



1    using System;
2    using System.Collections;
3    using System.Configuration;
4    using System.Data;
5    using System.Data.OleDb;
6    using System.Linq;
7    using System.Web;
8    using System.Web.Security;
9    using System.Web.UI;
10   using System.Web.UI.HtmlControls;
11   using System.Web.UI.WebControls;
12   using System.Web.UI.WebControls.WebParts;
13   using System.Xml.Linq;
15   public partial class BasketPrint : System.Web.UI.Page
16   {
17       public DataSet myDS;
20       protected void Page_Load(object sender, EventArgs e)
21       {
23       }
24       protected void btnSearch_Click(object sender, EventArgs e)
25       {
26           if (txtKeyword.Text == "")
27           {
28               return;
29           }
30           else
31           {
32               String key;
33               key = txtKeyword.Text.Trim();
35               //OpenConnection();
36               String myconnectionString;
37               myconnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " + Server.MapPath("Library Database Final_Nov_18.mdb");
38               OleDbConnection myCon = new OleDbConnection(myconnectionString);
39               myCon.Open();
41               //--------------------------------
43               //Generage_SQL();
44               string mySELECTStr, myFROMstr, myCriteriaStr, myOrderByStr, mySQLstring;
45               mySELECTStr = "SELECT Library.Title, Author.Lastname, Author.Firstname, Publisher.PublisherName, Library.PublishYear, Subject.SubjectName, MediaType.MediaTypeName, Library.NumberOfCopy , Library.DateUpdate, MediaType.MediaTypeID, Subject.SubjectID, Library.Description, Library.BiographyName, Library.DateUpdate ";
46               myFROMstr = "FROM Publisher INNER JOIN (MediaType INNER JOIN (Subject INNER JOIN (Author INNER JOIN Library ON Author.AuthorID = Library.AuthorID) ON Subject.SubjectID = Library.SubjectID) ON MediaType.MediaTypeID = Library.MediaTypeID) ON Publisher.PublisherID = Library.PublisherID ";
47               myCriteriaStr = " WHERE Title like '%" + key + "%'" + " OR Lastname like '%" + key + "%'" + " OR Firstname like '%" + key + "%'" + " OR PublisherName like '%" + key + "%'" + " OR PublishYear like '%" + key + "%'" + " OR SubjectName like '%" + key + "%'" + " OR MediaTypeName like '%" + key + "%'" + " OR BiographyName like '%" + key + "%'" + " OR Dateupdate like '%" + key + "%'";
48               myOrderByStr = " ORDER BY " + drlOrderBy.Text + " ASC";
49               mySQLstring = mySELECTStr + myFROMstr + myCriteriaStr + myOrderByStr;
51               //--------------------------------
53               //OpenAndFill();
54               OleDbCommand myCommand = new OleDbCommand(mySQLstring, myCon);
55               OleDbDataAdapter myDA = new OleDbDataAdapter(myCommand);
56               //OleDbDataAdapter myDA = new OleDbDataAdapter(mySQLstring, myCon);
57               DataSet myDS = new DataSet();
58               myDA.Fill(myDS, "Catalog");
60               //--------------------------------
61               //Show report
62               myGrid.DataSource = myDS.Tables[0];
63               myGrid.DataBind();
66           }
67       }
68       protected void btnDelete_Click(object sender, EventArgs e)
69       {
70   //Delete the chosen records then bind the grid again with the new dataset!
71           CheckBox iCheckbox = default(CheckBox);
73           foreach (GridViewRow row in myGrid.Rows)
74           {
75               iCheckbox = (CheckBox)row.FindControl("iChoose");
76               if (!iCheckbox.Checked)
77               {
78                   myDS.Tables("Catalog").Rows(row.RowIndex).Delete();
79               }
81           }
82       }
84   }        

5/4/2009 10:06:42 PM 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 52
Get it on Google Play
Get it on Apple App Store

After the deletion loop is finished, call DataBind on the grid to refresh it.

Steve Wellens

My blog
5/4/2009 10:56:28 PM

 But I got stuck with the error at that line, line 78!

5/4/2009 11:06:37 PM

 But I got stuck with the error at that line, line 78!

5/4/2009 11:08:30 PM

C# uses braces [Index] to access array elements:


Steve Wellens

My blog
5/4/2009 11:15:24 PM

Similar Artilces:

What's wrong with DataBind() in GridView control? The data in GridView can't be updated when the datasource have changed!
What's wrong with DataBind() in GridView control? The data in GridView can't be updated when the datasource have changed! I bind the different datasource to the Gridview when I change the node of TreeView, the GridView control always display the same data when I click different the node of TreeView control,why?but I can get the different data in GridView when I click the Button1 or Button2. //-------------------Program Code (You may save it as a ASPX file and run it)--------------------------------<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http:/...

First gridview's selected row doesn't update second gridview's objectdatasource
 HelloI got 2 gridviews on a page, each with its own ObjectDataSource. The first gridview fills itself just normally, no problem there. The second gridview needs to fill itself with other data, where the primary key is the primary key of the selected row of the first gridview.schematically:gridview1 row: IDfield, x, y, zrow: IDfield, x, y, z (-> this row is selected)row: IDfield, x, y, z gridview2 row:IDfield_of_selected_row_in_gridview1, a, b, c I tried to do this by configuring the ObjectDataSource behind gridview2 with a parameter pointing to gridview1.selectedValue. (by usin...

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;;= <br /> To: "" &lt;;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

2010: Can't register - can't download the software - can't register until I have the software
I have active maintenance on Rad Studio: From: Vicky Rassmisaengthong [mailto:Vicky.Rassmisaengthong@EMBARCADERO.COM] Sent: Wednesday, February 25, 2009 1:58 PM To: rgrossman Cc:; Ashley Cosentino Subject: Software Assurance Support for Tech III Inc PO# Credit Card Dear Embarcadero Technologies Support Customer, Welcome! You have been registered as the primary contact on support account number AM####### Herewith we confirm your Embarcadero Technologies support agreement covering: Qty 1 RAD Studio Enterprise Named User licens...

Can't figure out what's wrong with mail URL's
I have a problem in that when I click a URL within my mail client (Mozilla Thunderbird) - it downloads HTML and then displays it in IE with an address of C:\Documents and Settings\my name\Local Settings\Temp\name of HTML file This means that none of the associated images etc are displayed. The only way I can get the site to load properly is to copy and paste the URL into IE directly. Previously I was using Mozilla Firebird as my default browser. Anyone know what is going on here? Thanks! XP Pro SP1, IE 6.0, Mozilla Thunderbird 0.4 Paul Jackson <jackson.p.g@ayte...

Security startup's creed: you can't hack what you can't see
Security software startup Trusted Network Technologies Inc. is expected to come out of hiding this week. But it hopes its customers will appreciate the ability to make their networks and critical information systems more clandestine. The company is expected to disclose today that it has received $6 million in first-round funding from Charles River Ventures and Flagship Ventures, and it will unveil its access-management app, Identity, which sports a sneaky twist. According to company founder and CEO Stephen Gant, the app provides user access control by embedding a two-factor identity--o...

Dropdownlist on website
When I access an application written in 2.0 on my pc (uses XP) and on a laptop (using Vista), I can type into the dropdownlist to search for a record.  But other pc's (using XP) do not allow the user type to do a search.  Only the first letter of the word or the drop down are available to do a search.   Does anyone know why it would work with some pc's but not on others? I think this behaviour is in IE 7, check to see what versions of IE the PC's have that done work.-------------------------------------------------------...

Easy question, but I can't figure it out. Gridview nested in datalist .. I need to access the Gridview caption, but can't
To be more clear ...The datalist contains ItemIds, the gridview contains applications ids. When the page loads I need to check the database to see if the itemid / application id link already exists and if so check the checkbox. Everyhting works, except I can't get the itemid to check the DB with. Any suggestions, what am I doing wrong? I'm getting the object reference not set to the instance of an object error. TIA,Kyle 1 <asp:DataList ID="ItemsDataList" runat="server" DataSourceID="ObjectDataSource1"> 2 <ItemTemplate> 3 <h2>Part...

How to bind GridView's DataSource to an object's List<T> property??
Hi all, I really hope someone has a solution for this. I'm using ObjectDataSource throughout my project. I have an Order class which has, among other properties, a List<Product> ProductList property and a GetProductList method. I use GridView template field to present a list of Orders. For each column, I can, for example, bind a textbox to the OrderID property of my underlying Order object. I can achieve this by simply clicking the textbox's datbindings and associate the Text property to the exposed OrderID field in the underlying Order object. This works fine. I now ...

How to delete row from GridView control
Hello,  I am working on an ASP.NET 2.0 app, and I am trying to wire up a "Delete" button to a gridview control on a form. Here is the code for the ASP :  <asp:GridView ID="gvInConditions" runat="server" AutoGenerateColumns="true" OnRowDeleting="gvInConditions_RowDeleting" DataKeyNames="Condition_ID" >         <Columns>                <asp:CommandField ButtonType="Button" SelectText=&...

I can't stop a 'what's new' tab opening
Name: Bradley Crees Product: Shiretoko Summary: I can't stop a 'what's new' tab opening Comments: every time I open firefox it opens a tab with I can't stop it coming up, and it's affecting my ocd Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1 From URL: Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to ...

'Tab' control 's visible doesn't work.Why?
I use tab control in my applition. And I set visible=false, but it doesn't work. my code is: ----------------------------------------------- <asp:ScriptManager ID="ScriptManager1" runat="server" />  <div>   <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="138px" ActiveTabIndex="0"    Width="402px">    <ajaxToolkit:TabPanel runat="server" ID="Panel1" HeaderText="Tab1" Visible="f...

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

Web resources about - Can't remove a row in dataset that is Gridview's datasource -

Resources last updated: 11/21/2015 1:44:51 AM