public DataTable VideoSelectAll(string xmlFilePath, string keyWord) { if (!xmlFilePath.StartsWith("~/")) { xmlFilePath = "~/" + xmlFilePath; } DataSet ds1 = new DataSet(); ds1.ReadXml(HttpContext.Current.Server.MapPath(xmlFilePath), XmlReadMode.Auto); DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); dt.Columns.Add("ide"); dt.Columns.Add("title"); dt.Columns.Add("abstract"); dt.Columns.Add("ref"); dt.Columns.Add("param"); DataRow dr; if (ds1.Tables.Count != 1) { for (int i = 0; i < ds1.Tables[1].Rows.Count; i++) { dr = dt.NewRow(); dr["ide"] = ds1.Tables[1].Rows[i][3].ToString(); dr["title"] = ds1.Tables[1].Rows[i][0].ToString(); dr["abstract"] = ds1.Tables[1].Rows[i][1].ToString(); dr["ref"] = ds1.Tables[2].Rows[i][0].ToString(); dr["param"] = ds1.Tables[3].Rows[i][1].ToString(); dt.Rows.Add(dr); } } keyWord = keyWord == null || string.IsNullOrEmpty(keyWord.Trim()) ? "" : Common.ChangeToNoSymBol(Common.ReplaceRegex(keyWord.Trim().ToLower(), @"\")).Replace("_", @"\w"); var searchedRows = from DataRow row in dt.Rows where Regex.IsMatch(row["title"].ToString().ToLower(), keyWord) || Regex.IsMatch(row["abstract"].ToString().ToLower(), keyWord) select row; var obj = new object[dt.Columns.Count]; foreach (DataColumn dc in dt.Columns) { dt1.Columns.Add(dc.ColumnName); } foreach (DataRow row in searchedRows) { for (int i = 0; i < obj.Length; i++) { obj[i] = row[i]; } dt1.Rows.Add(obj); } return(dt1); }
public DataTable DistrictSelectAll( string DistrictName, string ProvinceIDs, //string DistrictIDs, string IsAvailable, string Priority, string SortByPriority ) { try { var dt = new DataTable(); var scon = new SqlConnection(connectionString); var cmd = new SqlCommand("usp_District_SelectAll", scon); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DistrictName", string.IsNullOrEmpty(DistrictName) ? dbNULL : (object)Common.ChangeToNoSymBol(DistrictName)); cmd.Parameters.AddWithValue("@ProvinceIDs", string.IsNullOrEmpty(ProvinceIDs) ? dbNULL : (object)ProvinceIDs); //cmd.Parameters.AddWithValue("@DistrictIDs", string.IsNullOrEmpty(DistrictIDs) ? dbNULL : (object)DistrictIDs); cmd.Parameters.AddWithValue("@IsAvailable", string.IsNullOrEmpty(IsAvailable) ? dbNULL : (object)IsAvailable); cmd.Parameters.AddWithValue("@Priority", string.IsNullOrEmpty(Priority) ? dbNULL : (object)Priority); cmd.Parameters.AddWithValue("@SortByPriority", string.IsNullOrEmpty(SortByPriority) ? dbNULL : (object)SortByPriority); SqlParameter errorCodeParam = new SqlParameter("@ErrorCode", null); errorCodeParam.Size = 4; errorCodeParam.Direction = ParameterDirection.Output; cmd.Parameters.Add(errorCodeParam); var sda = new SqlDataAdapter(cmd); sda.Fill(dt); if (errorCodeParam.Value.ToString() != "0") { throw new Exception("Stored Procedure 'usp_District_SelectAll' reported the ErrorCode : " + errorCodeParam.Value.ToString()); } return(dt); } catch (SqlException ex) { throw new Exception(ex.Number.ToString()); } catch (Exception ex) { throw new Exception(ex.Message); } }