예제 #1
0
        /// <summary>
        /// 返回匹配数据表
        /// </summary>
        /// <param name="OrgData">原始数据表</param>
        /// <param name="EqualsValues">匹配关键字</param>
        /// <param name="GetValues">匹配值</param>
        /// <returns>匹配数据表</returns>
        public static DataTable GetEquals(DataTable OrgData, List <string> EqualsValues, string GetValues)
        {
            DataTable DataSelect = OrgData.Clone();
            DataTable dt         = OrgData.Copy();
            DataView  dv         = dt.DefaultView;
            string    sqlselect  = "";

            try
            {
                string   Value  = StrClass.formatSqlStr(GetValues);
                string[] Values = new string[EqualsValues.Count];
                for (int i = 0; i < Values.GetLength(0); i++)
                {
                    Values[i] = Value;
                }
                sqlselect    = StrClass.SqlFormat(EqualsValues.ToArray(), Values, false);
                dv.RowFilter = sqlselect;
                dv.Sort      = EqualsValues[0] + " asc";
                DataSelect   = dv.ToTable().Copy();
                return(DataSelect);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
                return(null);
            }
        }
예제 #2
0
 /// <summary>
 /// 查找匹配值
 /// </summary>
 private void ValueSelect()
 {
     try
     {
         DataSelect.Clear();//清除缓存
         string   sqlselect = "";
         string[] varMen    = { "deptid_chr", "deptname_vchr", "pycode_chr" };
         string   Value     = formatSqlStr(txtbox.Text);
         string[] values    = { Value, Value, Value };
         sqlselect = StrClass.SqlFormat(varMen, values, false);
         DataRow[] z = dataSource.Select(sqlselect);
         for (int i = 0; i < z.GetLength(0); i++)
         {
             DataSelect.ImportRow(z[i]);
         }
         txtboxdate.DataSource = DataSelect;
         if (txtboxdate.Rows.Count > 0 && txtboxdate.SelectedRows.Count < 1)
         {
             txtboxdate.Rows[0].Selected = true;
         }
     }
     catch { }
 }