在语句中写两个查询 [英] Write two queries in a statement
本文介绍了在语句中写两个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在语句中写入两个查询
推荐答案
您可以在单个语句中使用写入两个查询;分号
例如string strquery =从表A中选择名称;从表格B中选择标记
但在你的例子中你有两个查询
一个(选择查询)使用执行阅读器
另一个(插入查询)使用执行非查询方法
so我觉得很难做到
如果有人有解决方案,请分享解决方案
you can write two query in a single statement using ; semicolon
e.g. string strquery="select name from table A;select mark from table B"
but in ur example u have two query
one(select query) uses execute reader
other one(Insert query) uses execute non query methode
so i think its difficult to do
if any one has solution , plz share the solution
试试这个
Try this
SqlCommand cmd = new SqlCommand(queryStr + " ; " + queryStr1 , conn);
更新:
updated:
SqlConnection conn = new SqlConnection(_connStr);
SqlCommand cmd = new SqlCommand(queryStr + ";" + queryStr1, conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
string eventtemp = dr["EventID"].ToString();
int eID = int.Parse(eventtemp);
string volunteertemp = dr["VolunteerID"].ToString();
int vID = int.Parse(volunteertemp);
//eventHelper.Add(new Event(eid , vID));
}
}
这篇关于在语句中写两个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文