默认情况下DataAdapter会根据选择的字段自动生成查询语句
方法一:修改DataAdapter的查询语句
比如这个问题
https://blog.csdn.net/shuyou612/article/details/46788475
由于MySQL中没有boolean类型,所以会用到tinyint类型来表示
就可以使用更改后的查询语句
type*1 as `type`
注意添加别名
直接读入的原始数据
方法二:
在DataAdapter.Fill()为相应的DataSet加入数据之后
手动修改DataSet
https://docs.microsoft.com/zh-cn/dotnet/api/system.data.datatable.rows?view=netframework-4.8【微软官方文档】
private void PrintRows(DataSet dataSet)
{
// For each table in the DataSet, print the values of each row.
foreach(DataTable thisTable in dataSet.Tables)
{
// For each row, print the values of each column.
foreach(DataRow row in thisTable.Rows)
{
foreach(DataColumn column in thisTable.Columns)
{
Console.WriteLine(row[column]);
}
}
}
}
private void AddARow(DataSet dataSet)
{
DataTable table;
table = dataSet.Tables["Suppliers"];
// Use the NewRow method to create a DataRow with
// the table's schema.
DataRow newRow = table.NewRow();
// Set values in the columns:
newRow["CompanyID"] = "NewCompanyID";
newRow["CompanyName"] = "NewCompanyName";
// Add the row to the rows collection.
table.Rows.Add(newRow);
}
再比如
int type = Convert.ToInt32(row["raw"].ToString());//使用字符串作为索引
//switch case
t = getType(type);
row["calculated"] = t;
可以在这里更改DataSet当中字段的名字,并且选择Source(以供Fill 方法使用)
方法三:
使用DataView,在数据源改变之后进行触发操作