我有这个代码,它给了我这个错误我试图很难解决这个但我没有运气。此方法用于通过给出select语句,tablename和dataset来更新mysql中的表。错误是“更新无法找到TableMapping ['tblapartments']或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;
}
}
这是用于调用方法的整个方法。
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);
答案 0 :(得分:1)
我弄清楚我做错了什么我需要mapp这里的表是固定代码
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;
}
}