日期:2014-05-20  浏览次数:20907 次

视图中得字段可不可以作为关键字查询
//视图代码:
create view View_TradingInquires --交易查询
With Encryption
as
select FleetNetwork.MachineID as 机器编号,FleetNetwork.MachineIP as 机器IP,TradingSerialNumber as 流水号,TradingTradTime as 时间,TradingEnchangType as 兑换方式,SerialList as 流水清单
from TradingInquires,FleetNetwork
where TradingInquires.MachineID=FleetNetwork.MachineID
with check option
//后台代码:
  private void button1_Click(object sender, EventArgs e)
  {
  string strsql = "select * from View_TradingInquires where TradingTradTime between '" + dateTimePicker1.Value + "' and '" + dateTimePicker2.Value + "'";
  ClassLibrary1.BusinssLayerProgrammer.Open();
  dataGridView1.DataSource= ClassLibrary1.BusinssLayerProgrammer.ExecuteQuery(strsql);
  }
我就是想通过2个dateTimePicker提取时间段,然后查询View_TradingInquires视图中这个时间段额信息
但是总提示TradingTradTime无效
不知道怎么办了

------解决方案--------------------
View里的column名字已经是 时间了

TradingTradTime as 时间

因此sql语句中要用时间

string strsql = "select * from View_TradingInquires where 时间 between '" + dateTimePicker1.Value + "' and '" + dateTimePicker2.Value + "'";

这样试一试