Click here to Skip to main content
15,888,062 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionhow to enable false of iframe page in asp.net not display false by jquery and css? Pin
kp 77715-Aug-14 4:54
professionalkp 77715-Aug-14 4:54 
AnswerRe: how to enable false of iframe page in asp.net not display false by jquery and css? Pin
ZurdoDev15-Aug-14 5:28
professionalZurdoDev15-Aug-14 5:28 
QuestionRequiredfield validator is not working Pin
murali_utr14-Aug-14 18:47
murali_utr14-Aug-14 18:47 
AnswerRe: Requiredfield validator is not working Pin
ZurdoDev15-Aug-14 5:29
professionalZurdoDev15-Aug-14 5:29 
QuestionHow to display certain records if user's search comes up empty? Pin
samflex14-Aug-14 6:20
samflex14-Aug-14 6:20 
SuggestionRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming14-Aug-14 6:45
mveRichard Deeming14-Aug-14 6:45 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex14-Aug-14 7:01
samflex14-Aug-14 7:01 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming14-Aug-14 7:28
mveRichard Deeming14-Aug-14 7:28 
The "-placeholder-" string in the SqlCommand constructor doesn't need to be changed. It's just there so that the command has some initial text which is obviously not a query. That text will be replaced later, once the full query has been built. (cmd.CommandText = sb.ToString())

The *** BASE QUERY HERE ... *** part needs to be the base query, up-to but not including the final "where" statement:
VB.NET
Dim sb As New StringBuilder("SELECT L.LocationId," & _
       "c.courseId, " & _
        "c.coursename, " & _
       "CASE WHEN L.Seating_Capacity - COALESCE(TS.TakenSeats,0) = 0 THEN 'Not Available' " & _
           " ELSE 'Available' END AS 'AvailableSeats'," & _
        "d.dateid, " & _
       " d.trainingDates, " & _
        "d.trainingtime, " & _
       " c.CourseDescription, " & _
       " i.instructorName, " & _
        "l.location " & _
      " FROM tblLocations L " & _
      " Inner Join tblCourses c on l.locationId = c.locationId " & _
      " Inner Join tblTrainingDates d on c.dateid=d.dateid " & _
     "  Inner Join tblCourseInstructor ic on c.courseId = ic.CourseId " & _
     "  Inner Join tblInstructors i on ic.instructorId = i.instructorId " & _
     "  OUTER APPLY (Select Count(*) TakenSeats " & _
     "  FROM tblTrainings T " & _
     "  where(L.LocationId = T.LocationId) " & _
     "  AND c.courseId = t.courseId) TS")

The code then appends the relevant filters to the StringBuilder instance to produce the final query.

As for returning one month's data if the search doesn't find anything, you'll need to modify the If dt.Rows.Count = 0 Then ... End If block to issue a new query to return the default data. Something like:
VB.NET
If dt.Rows.Count = 0 Then
    message.Text = "No matching records found."
    
    cmd.Parameters.Clear()
    cmd.Parameters.AddWithValue("@FromDate", Date.Today.AddMonths(-1))
    cmd.Parameters.AddWithValue("@EndDate", Date.Today)
    
    cmd.CommandText = "SELECT L.LocationId," & _
       "c.courseId, " & _
        "c.coursename, " & _
       "CASE WHEN L.Seating_Capacity - COALESCE(TS.TakenSeats,0) = 0 THEN 'Not Available' " & _
           " ELSE 'Available' END AS 'AvailableSeats'," & _
        "d.dateid, " & _
       " d.trainingDates, " & _
        "d.trainingtime, " & _
       " c.CourseDescription, " & _
       " i.instructorName, " & _
        "l.location " & _
      " FROM tblLocations L " & _
      " Inner Join tblCourses c on l.locationId = c.locationId " & _
      " Inner Join tblTrainingDates d on c.dateid=d.dateid " & _
     "  Inner Join tblCourseInstructor ic on c.courseId = ic.CourseId " & _
     "  Inner Join tblInstructors i on ic.instructorId = i.instructorId " & _
     "  OUTER APPLY (Select Count(*) TakenSeats " & _
     "  FROM tblTrainings T " & _
     "  where(L.LocationId = T.LocationId) " & _
     "  AND c.courseId = t.courseId) TS " & _
     " where d.trainingDates Between @FromDate And @EndDate"
    
    dt = GetData(cmd)
End If

You'll still need to modify the code which tries to find the "CurrentPage" label, in case the second query doesn't return any data either. There might not be a row, the row might not have any cells, or the cell might not contain a Label control called "CurrentPage"; any one of these things would cause your code to throw a NullReferenceException.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex14-Aug-14 17:07
samflex14-Aug-14 17:07 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming18-Aug-14 2:02
mveRichard Deeming18-Aug-14 2:02 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex18-Aug-14 2:54
samflex18-Aug-14 2:54 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming18-Aug-14 7:15
mveRichard Deeming18-Aug-14 7:15 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex18-Aug-14 8:04
samflex18-Aug-14 8:04 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming18-Aug-14 8:38
mveRichard Deeming18-Aug-14 8:38 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex18-Aug-14 10:55
samflex18-Aug-14 10:55 
QuestionAJAX control Pin
murali_utr13-Aug-14 23:09
murali_utr13-Aug-14 23:09 
GeneralRe: AJAX control Pin
Kornfeld Eliyahu Peter13-Aug-14 23:18
professionalKornfeld Eliyahu Peter13-Aug-14 23:18 
GeneralRe: AJAX control Pin
murali_utr14-Aug-14 18:00
murali_utr14-Aug-14 18:00 
QuestionGet original string from Guid Pin
Member 947380913-Aug-14 19:06
Member 947380913-Aug-14 19:06 
AnswerRe: Get original string from Guid Pin
Bernhard Hiller13-Aug-14 21:57
Bernhard Hiller13-Aug-14 21:57 
AnswerRe: Get original string from Guid Pin
Kornfeld Eliyahu Peter13-Aug-14 22:27
professionalKornfeld Eliyahu Peter13-Aug-14 22:27 
AnswerRe: Get original string from Guid Pin
Richard MacCutchan13-Aug-14 22:28
mveRichard MacCutchan13-Aug-14 22:28 
QuestionRe: Get original string from Guid Pin
Member 947380915-Aug-14 18:49
Member 947380915-Aug-14 18:49 
QuestionDynamic Linq Query in vb.net Pin
murali_utr12-Aug-14 18:51
murali_utr12-Aug-14 18:51 
AnswerRe: Dynamic Linq Query in vb.net Pin
Bernhard Hiller12-Aug-14 21:11
Bernhard Hiller12-Aug-14 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.