Hello all,
I want to update the database thru datagrid n also delete the contents of the selected row from the datagrid n then the database should be updated. however am getting a repeated error as to Unable to find Table[0] or Update unable to find TableMapping or DataTable 'Table'. error ....Below is the code snippet for ur reference....plz help me out on this ..this code is only for the delete event...however at the time of updating the database am getting error..plz help me solve this...

private void btnupdate_Click(object sender, EventArgs e)
        {
    
            foreach(DataGridViewRow row in dg1.SelectedRows) 
{ 
if (row.Index != dg1.Rows.Count - 1) 
{ 
dg1.Rows.RemoveAt(row.Index); 
} 
} 
da.Update(ds) ; 
}

You're modifying the collection inside of a foreach() statement -- Is that the error message you are receiving? I make a list of items to delete inside of the iteration then make a second pass to delete them:

private void RemoveQueryFromGrid()
    {
        List<DataRow> rowsToDelete = new List<DataRow>();
        foreach (DataRow row in _dtParameters.Rows)
        {
          if (Convert.ToString(row["GUID"]).Equals(guid))
            rowsToDelete.Add(row);
        }
        gridViewParameters.BeginDataUpdate();

        while (rowsToDelete.Count > 0)
        {
          rowsToDelete[0].Delete();
          rowsToDelete.RemoveAt(0);
        }

        _ds.AcceptChanges();
        gridViewParameters.EndDataUpdate();
    }

If this was not the error you were receiving then please post what the exception is.

laghaterohan,

What is and where is your problem?

Update/Delete (Urgent).

Is it a suitable title of this thread? Be sure about your question, use suitable title for a thread, and describe your problem along with error messages.

Don't use Urgent. It's bad manner.

hiii adatapost
plz pardon me . I hv written urgent 'coz i want solution to the problem asap.
Secondly , am having problem while updating the database table thru the gridview. I get the error msg..mentioned above...could u plz figure out what d problem is or what piece of code is missing...n fix my problem....?

thanks in advance....

Rohan

laghaterohan,

What is and where is your problem?

Is it a suitable title of this thread? Be sure about your question, use suitable title for a thread, and describe your problem along with error messages.

Don't use Urgent. It's bad manner.

I have a datagrid (editable). Whenvever i edit a row/column in the datagrid n click on the update button my database should be updated. Plz..find the code listed below and please help me out to fix the error :

private void btnupdate_Click(object sender, EventArgs e)
        {
    da.Update(ds);
           
        }

However i get the following error :
Update unable to find TableMapping or DataTable 'Table'.

Awating early reply.

da.Update(ds,"Tablename");

nah re...i tried..this one too but its not working for me ...i dont understand where the problem lies...my connection is perfect....but still i get error like...unable to find table "tablename" or no table at position 0 etc....really frustrated.....:(

cya
Rohan

da.Update(ds,"Tablename");

Paste the code from your dataset's designer or upload a sample project.

Platform : VS 2005 / C#.NET

I have a Datagrid(dg1). I fill this datagrid with the values contained in the table customer , by
clicking on the view button on the form ; to achieve this i have written the following code :

private void txtview_Click(object sender, EventArgs e)
        {
DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("Select * from customer", con);
            da.Fill(ds, "customer");
            dg1.DataSource = ds;
            dg1.DataMember = "customer";

}

I have another button "Update" on the same form . Now what i need to do is that whenever i edit any row in the datagrid manually , and then click on the update button present on the form , my database table should be updated and next time when i click on the View button i should see the changed values . For this i have written the following code:

private void btnupdate_Click(object sender, EventArgs e)
        {
  da.Update(ds);
}

Here i even tried , da.update(ds,"customer") but still its not working.


I get Errors like :

1) Update unable to find TableMapping or DataTable 'Table'

2)nable to find table "tablename" or no table at position 0

So kindly help me to solve this problem..

Thank you,
Rohan

You completely ignored what I said. This is more than likely a problem with your code-generated table adapter. Try recreating your table adapter or reconfiguring it in the designer or upload a sample project and I can try to help you further.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.