안녕하세요 저는 SQLDataSource로 생성 한 listView를 가지고 있는데, Sql은 URL에서 2 개의 매개 변수를 가져 와서 Select Query를 수행합니다.url 매개 변수의 값을 테스트 한 다음 SqlDataSource.SelectCommand를 코드 뒤에서 변경하십시오. C#
하지만 다음 SQL을 변경 첫번째 매개 변수의 값을 테스트 할이 문제가
경우 다른, 경우 사용 SelectCommand에 내 문은 항상 실패하고 심지어는 그들을 제거하고 페이지로드에서 쿼리를 변경할 때 경우 , 나는 selectCommand를 삭제하더라도 항상 SQLDataSource로 생성 한 원본 데이터를 반환합니다! 여기
내 ASPX 파일 여기
<asp:SqlDataSource ID="jobSearch" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="">
<SelectParameters>
<asp:QueryStringParameter Name="jobTitle" QueryStringField="jobTitle" Type="String" />
<asp:QueryStringParameter Name="joblocation" QueryStringField="jobLocation" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
의 일부가 내 .CS이
protected void Page_Load(object sender, EventArgs e)
{
// Request.QueryString["jobTitle"]
string jobTitle = Request.QueryString["jobTitle"];
string jobLocation = Request.QueryString["jobLocation"];
if (!string.IsNullOrEmpty(jobTitle) && !string.IsNullOrEmpty(jobLocation))
{
jobSearch.SelectCommand = "SELECT [jobId], [userId], [jobTitle], [jobBody], [jobPosition], [JobType], [salaryFrom], [salaryTo], [salaryType], [location], [jobCreated], [jobEnd], [jobViews], [applications] FROM [recruiter_Jobs] WHERE FREETEXT (([jobTitle]), @jobTitle) AND FREETEXT (([location]), @location) ORDER BY [jobCreated]";
test.Text = "1st if " + jobTitle;
}
else if (jobTitle == string.Empty && !string.IsNullOrEmpty(jobLocation) || string.IsNullOrWhiteSpace(jobTitle) && !string.IsNullOrEmpty(jobLocation) || string.IsNullOrEmpty(jobTitle) && !string.IsNullOrEmpty(jobLocation) || jobTitle == null && !string.IsNullOrEmpty(jobLocation))
{
jobSearch.SelectCommand = "SELECT [jobId], [userId], [jobTitle], [jobBody], [jobPosition], [JobType], [salaryFrom], [salaryTo], [salaryType], [location], [jobCreated], [jobEnd], [jobViews], [applications] FROM [recruiter_Jobs] WHERE FREETEXT (([location]), @location) ORDER BY [jobCreated]";
test.Text = "1st else if " + jobTitle;
}
else if (string.IsNullOrEmpty(jobTitle) && string.IsNullOrEmpty(jobLocation))
{
jobSearch.SelectCommand = "SELECT [jobId], [userId], [jobTitle], [jobBody], [jobPosition], [JobType], [salaryFrom], [salaryTo], [salaryType], [location], [jobCreated], [jobEnd], [jobViews], [applications] FROM [recruiter_Jobs] ORDER BY [jobCreated]";
test.Text = "last else if " + jobTitle;
}
}
내가 잘못하고있는 중이 야 어떤 생각을 파일입니다? 그것의 매개 변수 중 하나가 null의 경우 별도로 지정하지 않는 한
그냥 지금이 시도했지만 null 또는 빈 전체 텍스트 조건부 오류가 –
이 실제로 작동하지 않았다 내 SQL 잘못된 :-) 감사합니다 –