2013-10-09 1 views
0

날짜를 기준으로 세션 접두사 값에 따라 테이블 이름을 선택하는 검색 페이지입니다. 그러나 잘못된 열 이름 'ALV' . 'ALV'는 접두사 값 중 하나입니다.asp.net에서 세션 변수에 따라 두 날짜 사이의 데이터를 추출하는 동안

protected void Button1_Click(object sender, EventArgs e) 
    { 
     DateTime fromDate; 
     DateTime toDate; 

     if (DateTime.TryParse(txtFrom.Text, out fromDate) && DateTime.TryParse(txtTo.Text, out toDate)) 
     { 

      if (DropDownList1.SelectedItem.Text == "RouteToGrowth") 
      { 


       SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ToString()); 
       con.Open(); 
       string Prefix = Session["Prefix"].ToString(); 
       string SqlStatement1 = " select ActionID,rid ,h.UserID,h.Date,h.Tablename,h.Feedback,h.Status from history h,LoginTable l where l.UserId=h.UserID and h.Tablename='RouteToGrowthRecord_st' and l.Prefix=" + Prefix + " and date between @from and @to "; 
       SqlCommand cmd1 = new SqlCommand(SqlStatement1, con); 
       cmd1.Parameters.Add("@from", SqlDbType.Date).Value = fromDate; 
       cmd1.Parameters.Add("@to", SqlDbType.Date).Value = toDate; 
       cmd1.Parameters.Add("@Prefix", SqlDbType.VarChar).Value = Prefix; 
       cmd1.CommandType = CommandType.Text; 
       cmd1.ExecuteNonQuery(); 
       GridView1.DataBind(); 
       con.Close(); 
      } 
     } 
     else 
     { 
      ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Please fill the data correctly')</script>"); 
     } 
} 

답변

0

sqlstatement에 매개 변수를 지정하지 않아야합니까?

string SqlStatement1 = "select ActionID,rid ,h.UserID,h.Date,h.Tablename,h.Feedback,h.Status from history h,LoginTable l where l.UserId=h.UserID and h.Tablename='RouteToGrowthRecord_st' and [email protected] and date between @from and @to "; 
관련 문제