sql查询和linq以及datadrow的再次查询的组合使用
Posted wslk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql查询和linq以及datadrow的再次查询的组合使用相关的知识,希望对你有一定的参考价值。
try
{
//先判断数据是否完整,例如分差,学校表和专业是否导入
/*
var cx_fsd = from aa in sjklj.zy_fswc
where aa.nd >= DateTime.Now.Year - 1 && aa.nd <= DateTime.Now.Year
&& aa.lb.Contains("文科") && aa.lb.Contains("理科")
select aa;
if(cx_fsd.Count()==0)
{
this.Lbl_ts.Text = "zy_fswc:分数段数据没有或者不完整";
return;
}
*/
//还有zy_school以及zy_school_zy类似的查询---处理中
string conn = "Data Source=.;Initial Catalog=jfzytb;Integrated Security=True";
string cmdtxt = string.Format("select * from zy_school where nd={0} and lb in (‘{1}‘,‘{2}‘)",
DateTime.Now.Year - 1, "文科", "理科");
System.Data.DataTable dt_school = gj.sqlcx(conn, cmdtxt);
if (dt_school.Select("lb=‘文科‘").Count() == 0 || dt_school.Select("lb=‘理科‘").Count() == 0)
{
this.Lbl_ts.Text = " zy_school:高校与分数表数据不完整";
return;
}
cmdtxt = string.Format("select * from zy_school_zy where nd={0} and lb in (‘{1}‘,‘{2}‘)",
DateTime.Now.Year - 1, "文科", "理科");
System.Data.DataTable dt_school_zy = gj.sqlcx(conn, cmdtxt);
if (dt_school_zy.Select("lb=‘文科‘").Count() == 0 || dt_school_zy.Select("lb=‘理科‘").Count() == 0)
{
this.Lbl_ts.Text = "zy_school_zy:高校与专业以及分数表数据不完整";
return;
}
cmdtxt = string.Format("select * from zy_fswc where nd in ({0},{1}) and lb in (‘{2}‘,‘{3}‘)",
DateTime.Now.Year - 1,DateTime.Now.Year, "文科", "理科");
System.Data.DataTable dt_fc = gj.sqlcx(conn, cmdtxt);
if (dt_fc.Select("lb=‘文科‘").Count() == 0 || dt_fc.Select("lb=‘理科‘").Count() == 0
|| dt_fc.Select(string.Format("nd={0}", DateTime.Now.Year - 1)).Count() == 0 ||
dt_fc.Select(string.Format("nd={0}", DateTime.Now.Year)).Count() == 0)
{
this.Lbl_ts.Text = "zy_fswc:分数段数据没有或者不完整";
return;
}
var cx_xx = from aa in sjklj.zy_school
select aa;
foreach (var kk in cx_xx)
{
string dm = kk.dm;
string xxmc = kk.xxmc;
string pc = kk.pc;
int? nd = kk.nd;
string lb = kk.lb;
string zymc = "";
//文科,理科(学校代码和批次相同,可能类别文理科不同),同一批次,年度,类别,只要代码相同即可
//就指向的是同一个学校,因此,代码和学校名称必须完全检查(学校名单和专业表名单认真筛选查找修改核实),学校名称也匹配则更具有精确性
var cx_xxzy = from bb in sjklj.zy_school_zy
where bb.dm == dm && bb.pc == pc && bb.nd == nd && bb.lb == lb
select bb;//找到该学校的专业
if (cx_xxzy.Count() > 0)
{
foreach (var gg in cx_xxzy)
{
zymc += gg.zymc + " ";
}
}
if (zymc != string.Empty)
{
kk.zymc = zymc;
}
}
sjklj.SaveChanges();
System.Threading.Thread.Sleep(200);
this.Lbl_ts.Text = "专业已经附加到学校名单表中";
}
catch (Exception err)
{
this.Lbl_ts.Text = err.Message;
}
以上是关于sql查询和linq以及datadrow的再次查询的组合使用的主要内容,如果未能解决你的问题,请参考以下文章