Visual Studio 下 C# 自定义DataView 空间的显示信息 ->自定义字段(修改 DataAdapeter读出的原始数据)

默认情况下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,在数据源改变之后进行触发操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值