下面的代碼工作正常,一個問題顯示了許多記錄,它假設只顯示一個。 (例如:如果從用戶的UserInfo表有10個廣告到廣告表,其中這些廣告5具有相似的查詢字符串結果值值,所以他重複用戶的5倍它假設出現一次什麼他所擁有的廣告,其中Wtag列。)DISTINCT進入SQL語句不能很好地工作
if (Request.QueryString["Searchfor"] != null)
{
using (SqlConnection srcbizhsql = new SqlConnection(sc))
{
srcbizhsql.Open();
SqlDataAdapter DAsearchbiz = new SqlDataAdapter(@"SELECT DISTINCT UI.[UID],UI.[Country],UI.[State],UI.[City],UI.[Logo],UI.[Website],UI.[UsrType],UI.[BizCateg],UI.[BizSubCateg],UI.[Twitter],UI.[GooglePlus],UI.[Facebook],UI.[CompNme],UI.[RegDate] ,SUBSTRING([CompDesc],1,40) AS CompDesc ,AD.[Wtags] FROM UserInfo AS UI , ads AS AD WHERE UI.UID = AD.UID and UI.[Country]= @Location AND UI.[UsrType]= 'Business' AND CHARINDEX(@Wtag, AD.[Wtags])>0 ORDER BY UI.[RegDate] DESC", sc);
DataSet DSsrchBiz = new DataSet();
DAsearchbiz.SelectCommand.Parameters.AddWithValue("@Location", cookie.Value);
DAsearchbiz.SelectCommand.Parameters.AddWithValue("@Wtag", result);
DAsearchbiz.Fill(DSsrchBiz);
SrchbizHomLstviw.DataSource = DSsrchBiz.Tables[0];
SrchbizHomLstviw.DataBind();
SrchMultiView.ActiveViewIndex = 1;
RebindAds();
RebindJobs();
}
}
查詢複製到SSMS和手動檢查什麼不同呢? – CodeNotFound
@CodeNotFound我之前嘗試過,但在SSMS中很難做到,因爲查詢字符串假設存在 – samo
FOr me我認爲這是SUBSTRING([CompDesc],1,40)或AD。[Wtags]導致您的問題 – CodeNotFound