//根据起始日期,截止日期和参数搜索数据库 public DataSet search(DbArgs args) { string queryArgs = "日期"; bool[] tmp = { args.openingPrice, args.closingPrice, args.maxPrice, args.minPrice }; string[] tmpStr = { "开盘价", "收盘价", "最高价", "最低价" }; for (int i = 0; i < tmp.Length; i++) { if (tmp[i]) { queryArgs += ", " + tmpStr[i]; } } string queryStr = "select " + queryArgs + " from stock where 日期 >= '" + args.beginDate.ToShortDateString() + "' and 日期 <= '" + args.endDate.ToShortDateString() + "'"; using (var connection = openConnection()) { SqlCommand cmd = connection.CreateCommand(); cmd.CommandText = queryStr; cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); return(ds); } }
//根据起始日期,截止日期和参数搜索数据库 public DataSet search(DbArgs args) { try { return(dal.search(args)); } catch { return(null); } }