查询
开发工具与关键技术:vs 查询
作者:周乐献
撰写时间:2019/5.8
查询,一个简单却无比重要的词,随着网络的日益发展它已经深深的进入到我们的生活当中。当我们不知道路时,简单——拿出手机,打开数据——进入地图——输入你想要去的地方点击查找就能得到结果。当你某个问题不会时,查一下即可。想要知道从xx到xx的车票是多少也可以拿出手机来查找。可以说查这个字的意义是巨大的。
让我们以学校为例子简单的了解一下查询是怎么实现的。
首先它需要先绑定学校学生的数据。
tabStudentImport = layuiTable.render({
elem: "#tabStudentImport",
cols: [[
{ type: 'numbers', title: '序号' },
{ field: 'StudentNumber', title: '学号' },
{ field: 'StudentName', title: '姓名', width: 98 },
{ field: 'StudentIDNum', title: '身份证号' },
{ field: 'StudentSex', title: '性别', width: 58 },
{ field: 'AcademeName', title: '学院' },
{ field: 'SpecialtyName', title: '专业' },
{ field: 'GradeName', title: '年级', width: 68 },
{ field: 'ClassName', title: '班级', width: 98 },
{ field: 'UserNuber', title: '账号' },
]],
page: {
limit: 10,
limits: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],
},
data: [],
});
function tabStudentSearch() {
var AcademeID = $("#searchAcademeID").val();
if (AcademeID == "" || AcademeID == undefined) {
AcademeID = 0;
}
var GradeID = $("#searchGradeID").val();
if (GradeID == "" || GradeID == undefined) {
GradeID = 0;
}
var ClassID = $("#searchClassID").val();
if (ClassID == "" || ClassID == undefined) {
ClassID = 0;
}
var StudentInfo = $("#searchStudentNumber").val();
if (StudentInfo == undefined) {
StudentInfo = "";
}
tabStudent = layuiTable.reload("tabStudent", {
url: "/ExaminationManagement/SetExaminee/SelectStudentAll",
page: {
curr: 1
},
where: {
AcademeID: AcademeID,
GradeID: GradeID,
ClassID: ClassID,
StudentInfo: StudentInfo,
}
});
}
当学校领导想要知道通信与信息工程学院,2016级,01141601有那些人时他就可以从学校的表单上查询即可。
多表查询
单表查询
单表查询相对于多表查询不同的是单表查询的是个体,它的ID具有唯一性,而多表查询更多的是查询某一个集体,它的内容一般包括着很多的个体。
public ActionResult SelectStudentById(int StudentID)
{
try
{
Student student = (from tbStudent in myModels.PW_Student
join tbUser in myModels.PW_User on tbStudent.UserID equals tbUser.UserID
where tbStudent.studentID == StudentID
select new Student
{
studentID = tbStudent.studentID,
UserID = tbStudent.UserID,
AcademeID=tbStudent.AcademeID,
SpecialtyID=tbStudent.SpecialtyID,
GradeID=tbStudent.GradeID,
ClassID=tbStudent.ClassID,
StudentIDNum=tbStudent.StudentIDNum,
StudentNumber=tbStudent.StudentNumber,
UniformAuthenticationCode=tbUser.UniformAuthenticationCode,
StudentName=tbStudent.StudentName,
StudentSex=tbStudent.StudentSex,
UserNuber=tbUser.UserNuber,
Password=tbUser.Password
}).Single();
return Json(student, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
Console.WriteLine(e);
return Json("failed", JsonRequestBehavior.AllowGet);
}
}