0

i have this code and it is giving me this error i tried really hard to solve this but i am getting no luck. This method is used to update a table from mysql by giving select statement, tablename and dataset. The error is "Update unable to find TableMapping['tblapartments'] or DataTable 'tblapartments'."

public bool UpdateDatabase(string SelectStat, string tablename, DataSet dataset)
{
    try
    {
        MySqlDataAdapter da = new MySqlDataAdapter(SelectStat, _conn);
        MySqlCommandBuilder MYCB = new MySqlCommandBuilder(da);
        DataSet ds = dataset;
        da.MissingSchemaAction = MissingSchemaAction.AddWithKey;

        da.Update(ds, tablename);
        MySqlConnection.ClearAllPools();
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }

}

this is the whole method used for calling the method.

 DataTable dt = (DataTable)dtgApartList.DataSource;
 DataSet ds = GlobalVariables.Adap.GetTableCus("SELECT NameNo, MaintenanceFee, AdminFee  FROM tblapartments WHERE BuildingID = '" + cmbBuildingName.SelectedValue.ToString() + "'");
 ds.Tables[0].Merge(dt, false);
 GlobalVariables.Adap.UpdateDatabase("SELECT NameNo, MaintenanceFee, AdminFee  FROM tblapartments WHERE BuildingID = '" + cmbBuildingName.SelectedValue.ToString() + "'", "tblapartments", ds); 
2
  • 1
    Can you list the code that calls this? Commented Oct 25, 2011 at 14:02
  • I editid to show you how i am calling the method Commented Oct 25, 2011 at 14:14

1 Answer 1

1

I figured out what i was doing wrong i needed to mapp the tables here is the fixed code

public bool UpdateDatabase(string SelectStat, string tablename, DataSet dataset)
{
    try
    {
        MySqlDataAdapter da = new MySqlDataAdapter(SelectStat, _conn);
        MySqlCommandBuilder MYCB = new MySqlCommandBuilder(da);
        DataSet ds = dataset;
        da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
        //Added this
        ITableMapping testing = da.TableMappings.Add(tablename,"Table");
        da.Update(ds, tablename);
        MySqlConnection.ClearAllPools();
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }

}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.