asp.net sql或集合问题
以下是Placementsearch.aspx.cs上的代码asp.net sql或集合问题,asp.net,sql,Asp.net,Sql,以下是Placementsearch.aspx.cs上的代码 protected void Ok_Click(object sender, EventArgs e) { try { if (Page.IsValid) { int course_id = Convert.ToInt32(course.SelectedValue); int pass
protected void Ok_Click(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
{
int course_id = Convert.ToInt32(course.SelectedValue);
int passoutYear = Convert.ToInt32(passout.SelectedValue);
int currentBacklog = Convert.ToInt32(currrentBacklogDDL.SelectedValue);
int sex = Convert.ToInt32(gender.SelectedValue);
int? eGap = null;
int? firstYrPercent = null;
int? secondYrPercent = null;
int? thirdYrPercent = null;
int? finalYearpercent = null;
int? currentDegeePercentage = null;
int? highSchoolPercentge = null;
int? higherSchoolPercentage = null;
int? grauationPercentage = null;
int? diplomaPercentage = null;
int? noOfAtkt = null;
DateTime? date = null;
if (!string.IsNullOrEmpty(DOB.Text.Trim()))
{
string dateOfBirth = DOB.Text.Trim();
DateTime birthDate = DateTime.ParseExact(dateOfBirth, "dd/mm/yyyy", System.Globalization.CultureInfo.InvariantCulture);
string outPut = birthDate.ToString("mm/dd/YYYY");
date = Convert.ToDateTime(outPut);
}
if (!String.IsNullOrEmpty(educationGap.Text.Trim()))
{
eGap = Convert.ToInt32(educationGap.Text.Trim());
}
if (!string.IsNullOrEmpty(firstYear.Text))
{
firstYrPercent = Convert.ToInt32(firstYear.Text.Trim());
}
if (!string.IsNullOrEmpty(secondYear.Text.Trim()))
{
secondYrPercent = Convert.ToInt32(secondYear.Text.Trim());
}
if (!string.IsNullOrEmpty(thirdYear.Text))
{
thirdYrPercent = Convert.ToInt32(thirdYear.Text.Trim());
}
if (!string.IsNullOrEmpty(finalyear.Text.Trim()))
{
finalYearpercent = Convert.ToInt32(finalyear.Text.Trim());
}
if (!string.IsNullOrEmpty(currentDegree.Text.Trim()))
{
currentDegeePercentage = Convert.ToInt32(currentDegree.Text.Trim());
}
if (!string.IsNullOrEmpty(higherSchool.Text.Trim()))
{
higherSchoolPercentage = Convert.ToInt32(higherSchool.Text.Trim());
}
if (!string.IsNullOrEmpty(highSchool.Text.Trim()))
{
highSchoolPercentge = Convert.ToInt32(highSchool.Text.Trim());
}
if (!string.IsNullOrEmpty(graduation.Text.Trim()))
{
grauationPercentage = Convert.ToInt32(graduation.Text.Trim());
}
if (!string.IsNullOrEmpty(diploma.Text.Trim()))
{
diplomaPercentage = Convert.ToInt32(diploma.Text.Trim());
}
if (!string.IsNullOrEmpty(atkt.Text.Trim()))
{
noOfAtkt = Convert.ToInt32(atkt.Text.Trim());
}
Dictionary<string, object> paramList = new Dictionary<string, object>();
paramList.Add("@courseId", course_id);
paramList.Add("@passoutYear", passoutYear);
paramList.Add("@currentBacklog", currentBacklog);
paramList.Add("@sex", sex);
paramList.Add("@eGap", eGap);
paramList.Add("@firstYrPercent", firstYrPercent);
paramList.Add("@secondYrPercent", secondYrPercent);
paramList.Add("@thirdYrPercent", thirdYrPercent);
paramList.Add("@finalYearpercent", finalYearpercent);
paramList.Add("@currentDegeePercentage", currentDegeePercentage);
paramList.Add("@highSchoolPercentge", highSchoolPercentge);
paramList.Add("@higherSchoolPercentage", higherSchoolPercentage);
paramList.Add("@grauationPercentage", grauationPercentage);
paramList.Add("@diplomaPercentage", diplomaPercentage);
paramList.Add("@noOfAtkt", noOfAtkt);
paramList.Add("@date", date);
StringBuilder branchId= new StringBuilder();
foreach (ListItem li in branch.Items)
{
if (li.Selected)
{
branchId.Append(Convert.ToInt32(li.Value));
}
}
DataTable dt = searchManager.GetEligibleStudent(paramList, branchId);
}
}
catch (Exception ex)
{
COMMON.logger.Error("Error On Button click Ok", ex);
}
protectedvoid确定\u单击(对象发送方,事件参数e)
{
尝试
{
如果(第页有效)
{
int course\u id=Convert.ToInt32(course.SelectedValue);
int passoutYear=Convert.ToInt32(passout.SelectedValue);
int currentBacklog=Convert.ToInt32(currentbacklogddl.SelectedValue);
int sex=Convert.ToInt32(gender.SelectedValue);
int?eGap=null;
int?firstYrPercent=null;
int?secondYrPercent=null;
int?thirdYrPercent=null;
int?finalyearcent=null;
int?CurrentDegePercentage=null;
int?高中百分比ge=null;
int?higherSchoolPercentage=null;
int?grauationPercentage=null;
int?百分比=null;
int?noofatt=null;
DateTime?date=null;
如果(!string.IsNullOrEmpty(DOB.Text.Trim()))
{
字符串dateOfBirth=DOB.Text.Trim();
DateTime birthDate=DateTime.ParseExact(dateOfBirth,“dd/mm/yyyy”,System.Globalization.CultureInfo.InvariantCulture);
字符串输出=birthDate.ToString(“mm/dd/YYYY”);
日期=Convert.ToDateTime(输出);
}
如果(!String.IsNullOrEmpty(educationGap.Text.Trim()))
{
eGap=Convert.ToInt32(educationGap.Text.Trim());
}
如果(!string.IsNullOrEmpty(firstYear.Text))
{
firstYrPercent=Convert.ToInt32(firstYear.Text.Trim());
}
如果(!string.IsNullOrEmpty(secondYear.Text.Trim()))
{
secondYrPercent=Convert.ToInt32(secondYear.Text.Trim());
}
如果(!string.IsNullOrEmpty(thirdYear.Text))
{
thirdYrPercent=Convert.ToInt32(thirdYear.Text.Trim());
}
如果(!string.IsNullOrEmpty(finalyear.Text.Trim()))
{
finalyear=Convert.ToInt32(finalyear.Text.Trim());
}
如果(!string.IsNullOrEmpty(currentDegree.Text.Trim()))
{
currentDegeePercentage=Convert.ToInt32(currentdege.Text.Trim());
}
如果(!string.IsNullOrEmpty(higherSchool.Text.Trim()))
{
higherSchoolPercentage=Convert.ToInt32(higherSchool.Text.Trim());
}
如果(!string.IsNullOrEmpty(highSchool.Text.Trim()))
{
highSchool Percentge=Convert.ToInt32(highSchool.Text.Trim());
}
如果(!string.IsNullOrEmpty(gradication.Text.Trim()))
{
grauationPercentage=Convert.ToInt32(gradication.Text.Trim());
}
如果(!string.IsNullOrEmpty(diplicial.Text.Trim()))
{
文凭百分比=Convert.ToInt32(文凭.Text.Trim());
}
如果(!string.IsNullOrEmpty(atkt.Text.Trim()))
{
noOfAtkt=Convert.ToInt32(atkt.Text.Trim());
}
字典参数列表=新字典();
paramList.Add(“@courseId”,课程id);
paramList.Add(“@passoutYear”,passoutYear);
paramList.Add(“@currentBacklog”,currentBacklog);
参数列表。添加(“@sex”,sex);
参数列表。添加(“@eGap”,eGap);
添加(“@firstYrPercent”,firstYrPercent);
添加(“@secondYrPercent”,secondYrPercent);
添加(“@thirdYrPercent”,thirdYrPercent);
参数列表。添加(“@finalyearcent”,finalyearcent);
paramList.Add(“@currentDegeePercentage”,currentDegeePercentage);
参数列表。添加(“@highSchoolPercentge”,highSchoolPercentge);
添加(“@higherSchoolPercentage”,higherSchoolPercentage);
参数列表。添加(“@grauationPercentage”,grauationPercentage);
paramList.Add(“@emplicapercentage”,emplicapercentage);
参数列表。添加(“@noofatt”,noofatt);
参数列表。添加(“@date”,date);
StringBuilder branchId=新建StringBuilder();
foreach(在branch.Items中列出项目li)
{
如果(li.选定)
{
Append(Convert.ToInt32(li.Value));
}
}
DataTable dt=searchManager.GetEligibleStudent(参数列表,branchId);
}
}
捕获(例外情况除外)
{
COMMON.logger.Error(“单击确定按钮时出错”,ex);
}
这是从上面页面调用的方法。此方法位于searchstudentDAO.cs类中
public DataTable GetEligibleStudent(Dictionary<string, object> paramList, StringBuilder branchId)
{
try
{
string cmd = @"SELECT * FROM [tbl_students] WHERE course_id=@courseId
AND branch_id IN(" + branchId + @")
AND (@firstYrPercent is null OR first_year_percent>=@firstYrPercent)
AND (@secondYrpercent is null OR second_year_percent>=@secondYrPercent)
AND (@thirdYrPercent is null OR third_year_percent>=@thirdYrPercent)
AND (@finalYearpercent is null OR final_year_percent>=@finalYearpercent)
AND (@currentDegeePercentage is null OR current_degree_percent>=@currentDegeePercentage)
AND (@passoutYear is null OR passing_year>=@passoutYear)
AND (@currentBacklog is null OR current_backlog<=@currentBacklog)
AND gender=@sex
AND (@eGap is null OR gapin_education<=@eGap)
AND (@highSchoolPercentge is null OR highschool_percentage>=@highSchoolPercentge)
AND (@higherSchoolPercentage is null OR ssc_percentage>=@higherSchoolPercentage)
AND (@grauationPercentage is null OR graduation_percentage>=@grauationPercentage)
AND (@diplomaPercentage is null OR diploma_percentage>=@diplomaPercentage)
AND (@noOfAtkt is null OR number_of_ATKT<=@noOfAtkt)
AND (@date is null OR DOB>=@date)";
//string cmd = "SELECT * FROM [tbl_branch] WHERE course_id IN(" + sb + ")";
if (dbManager.OpenConnection())
{
dt = dbManager.GetDataTable(cmd, paramList);
return dt;
}
else
{
dt = null;
return dt;
}
}
catch (Exception ex)
{
COMMON.logger.Error("Error ON Method Getting Eligible Students:SearchStudentDAO", ex);
dt = null;
return dt;
throw;
}
finally
{
dbManager.CloseConnection();
}
}
公共数据表GetEligibleStudent(字典参数列表,StringBuilder branchId)
{
尝试
{
字符串cmd=@“从[tbl_学生]中选择*,其中课程id=@courseId
和中的分支id(“+branchId+@”)
和(@firstYrPercent为空或first_year_percent>=@firstYrPercent)
和(@secondYrpercent为空或second_year_percent>=@secondYrpercent)
和(@thirdYrPercent为空或第三年百分比>=@thirdYrPercent)
和(@finalYearpercent为空或final_year_percent>=@finalYearpercent)
和(@currentDegeePercentage为空或currentDegeePercentage>=@currentDegeePercentage)
和(@passoutYear)
public DataTable GetDataTable(string strCmd, Dictionary<string, object> paramList)
{
try
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(strCmd, _sqlCon);
foreach (KeyValuePair<string, object> kvp in paramList)
{
cmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
return dt;
}
catch (Exception ex)
{
logger.Error("Error when executing Query " + strCmd, ex);
throw;
return null;
}
}