【发布时间】:2018-11-13 22:48:19
【问题描述】:
有一个程序可以构建一个select语句,例如
public void GetLog(DataSet dataSet, string tableName, string userCase){
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
tmpSql = @"select * from table1 t1
join table2 on t1.key=t2.key
where 1=1 and "+userCase
cmd.CommandType = CommandType.Text;
adapter = new OracleDataAdapter(cmd);
adapter.SelectCommand = cmd;
adapter.Fill(dataSet, tableName);
}
两个表都包含一个列,例如“NAME”,当 userCase 类似于“name='BLABLA'”时,我有异常“ora-00918 列定义不明确”。我想将表名添加到 userCase 中。如何获取包含此列的表的信息,以便将其添加到 var userCase "table1.name='BLABLA'" 中。 userCase 可以包含 table1 或 table2 中的任何列。我需要更改过程,以便它通过 sql 或表名获取元数据
【问题讨论】:
-
如果两个表都有一个名为
NAME的列,那么只有知道您数据的人才能为您回答这个问题。 -
这只是示例,sql和字段可能是其他的。我想为构建 sql 制定通用方法。
-
那么任何使用
userCase调用这个函数的进程都必须知道必要列所属的表 -
正如我之前所说的,这只是一个例子,我需要通用的方法来构建 sql。我尝试使用DataTableMapping,DataTableMapping mapping = adapter.TableMappings.Add("table1", "table1");但映射不包含表描述
-
我不确定你想做什么是可能的。您可能需要考虑为不同的查询使用不同的方法。
标签: c# oracle dataset metadata