Brinkbeibia
New Member
I have a stored procedure which I am calling which will return data from a table.But when I try to populate an .aspx with the data it skips my method from doing it because my method is based on whether a reader detects rows.Here is my method:\[code\]private void editExhibit(int expenseID)//new{ saveExhibitBtn.Text = "Update Exhibit"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString()); SqlCommand cmd = new SqlCommand("p_CaseFiles_Exhibits_RetrieveExhibitDetails", conn); cmd.CommandType = CommandType.StoredProcedure; //cmd.Parameters.AddWithValue("@ExhibitID", expenseID); cmd.Parameters.Add(new SqlParameter("@ExhibitID", SqlDbType.Int)); cmd.Parameters["@ExhibitID"].Value = http://stackoverflow.com/questions/12587650/expenseID; bool hasAttachments = false; string investigatorID =""; //bool alreadyInvoiced = false; bool isExpenseOwner = false; string fileID = "-1"; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows)//////////////////////craps out here bcause hasRows is false.... { reader.Read(); fileID = reader["FileID"].ToString(); ddlCaseFiles.SelectedValue = http://stackoverflow.com/questions/12587650/fileID; ddlCaseFiles.Enabled = false; // retrieve exhibit details here hasAttachments = (bool)reader["HasAttachments"]; investigatorID = reader["InvestigatorID"].ToString(); if (Session["InvestigatorID"].ToString() == investigatorID) { isExpenseOwner = true; } txtDateReceived.Value = http://stackoverflow.com/questions/12587650/reader["SeizeDate"].ToString(); ddlReceivedBy.SelectedValue = http://stackoverflow.com/questions/12587650/reader["SeizedByInvestigatorID"].ToString(); txtTimeReceived.Value = http://stackoverflow.com/questions/12587650/reader["SeizeTime"].ToString(); txtWhyHowReceived.Value = http://stackoverflow.com/questions/12587650/reader["SeizeAuthority"].ToString(); txtReceivedLocation.Value = http://stackoverflow.com/questions/12587650/reader["SeizeLocation"].ToString(); txtOurItemNum.Value = http://stackoverflow.com/questions/12587650/reader["NewExhibitOutItemNumber"].ToString();//////////// txtTheirItemNum.Value = http://stackoverflow.com/questions/12587650/reader["ClientItemNum"].ToString(); txtBagNum.Value = http://stackoverflow.com/questions/12587650/reader["BagNumber"].ToString(); txtBoxNum.Value = http://stackoverflow.com/questions/12587650/reader["BoxNumber"].ToString(); txtComment.Value = http://stackoverflow.com/questions/12587650/reader["ExhibitDecriptionPlainText"].ToString(); } } catch (SqlException ex) { ErrorLogger.Log(ex.Number, "NewExhibit.aspx - editExhibit - Retrieve Details", ex.Message); }\[/code\]Here is my stored procedure:\[code\]SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[p_CaseFiles_Exhibits_RetrieveExhibitDetails] @FilterField nvarchar(max)=null, @FilterQuery nvarchar(max)=null, @SortName nvarchar(max)='SeizeDate, SeizeTime ', @SortOrder nvarchar(max)='desc', @ExhibitID intasSET CONCAT_NULL_YIELDS_NULL OFFdeclare @Command nvarchar(max)Select @Command = 'select E.ExhibitID,convert(nvarchar,SeizeDate,111) as ''SeizeDate'',SeizeTime,ExhDesc,E.InvestigatorID as ''EnteredBy'' ,E.SeizedByInvestigatoID as ''SeizedBy'',SBI.ActiveInvestigator, SBI.FName+'' '' + SBI.LName as ''SeizedByName'', E.FileID,[FileName] ,Investigators.FName,Investigators.LName,SzAuthority,Location,ItemID,SubItemID1,SubItemID2,SubItemID3,PageSerial,ClientItemNum,Privileged ,Private,E.HasAttachments,ItemEntryGradeID,BagNumber,BoxNumber,PL.PropertyId,P.PropertyTypeID,P.PropertyMakeID,P.PropertyModelID,SerialNumber,ColorID ,cast(ItemID as varchar)+''-''+cast(SubItemID1 as varchar)+''-''+cast(SubItemID2 as varchar)+''-''+cast(SubItemID3 as varchar) as ''ItemNumber'',StoredLocally from CaseFileExhibits E join Investigators on E.InvestigatorID = Investigators.InvestigatorID join Investigators SBI on SBI.InvestigatorID=E.SeizedByInvestigatoID join CaseFiles on E.FileID = CaseFiles.FileID left join CaseFileExhibitPropertyLink PL on E.ExhibitID=PL.ExhibitID left join Element09a_Properties P on P.PropertyID=PL.PropertyId left join ElementPropertyTypes PT on PT.PropertyTypeID=P.PropertyTypeID left join ElementPropertyMakes PM on PM.PropertyMakeID=P.PropertyMakeID left join ElementPropertyModels PMD on PMD.PropertyModelID=P.PropertyModelID where E.ExhibitID='+convert(nvarchar,@ExhibitID);if(@FilterQuery is not null)begin select @Command+=' and '+@FilterField+ ' like '''+@FilterQuery+''' ';endselect @Command+=' order by '+@SortName+' '+@SortOrder\[/code\]So according to the stored procedure I only need to pass in the \[code\]exhibitID\[/code\], which I did.