public List <FolderDTO> getsubfolder(int folderid) { FolderDTO dto = new FolderDTO(); List <FolderDTO> list = new List <FolderDTO>(); string connString = @"Data Source=AZAZ-PC\SQLEXPRESS2012 ;Initial Catalog=Assignment8 ; User Id=sa;Password=1234"; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); var query = String.Format("Select f.ID , f.Name, f.ParentFolderId ,f.CreatedBy,f.CreatedOn from Users u , Folder f where u.UserID = f.CreatedBy and f.ParentFolderId = '{0}';", folderid); SqlCommand command = new SqlCommand(query, conn); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { var dto1 = FillDTO(reader); if (dto1 != null) { list.Add(dto1); } } } return(list); }
private FolderDTO FillDTO(SqlDataReader reader) { var dto = new FolderDTO(); dto.FolderId = reader.GetInt32(0); dto.Name = reader.GetString(1); dto.ParentFolderId = reader.GetInt32(2); dto.CreatedBy = reader.GetInt32(3); dto.CreatedOn = reader.GetDateTime(4); return(dto); }
public int Save(FolderDTO dto) { int uid = 0; string connString = @"Data Source=AZAZ-PC\SQLEXPRESS2012 ;Initial Catalog=Assignment8 ; User Id=sa;Password=1234"; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); String sqlQuery = ""; { sqlQuery = String.Format("INSERT INTO dbo.Folder(Name,ParentFolderId,CreatedBy,createdOn,IsActive) VALUES('{0}','{1}','{2}','{3}','{4}');", dto.Name, dto.ParentFolderId, dto.CreatedBy, dto.CreatedOn, dto.IsActive); } SqlCommand command = new SqlCommand(sqlQuery, conn); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { uid = reader.GetInt32(reader.GetOrdinal("ID")); } } return(uid); }