多表查询实例
public static DataTable GetAllFlow_Run_PrcsByPrcsFlagAndUserId(int prcsFlag, string userId)
{
string sqlAll = "select a.*,b.*,c.* from Flow_Run a,Flow_Type
b,Flow_Run_Prcs c where a.RunId=c.RunId and a.FlowId=b.FlowId and
c.PrcsFlag=" + prcsFlag + " and c.UserId='" + userId + "'";
SqlCommand cmd = new SqlCommand(sqlAll, DBHelper.Connection);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("RunId", typeof(System.Int32));
dt.Columns.Add("RunName", typeof(System.String));
dt.Columns.Add("FlowId", typeof(System.Int32));
dt.Columns.Add("BeginUser", typeof(System.String));
dt.Columns.Add("FlowName", typeof(System.String));
dt.Columns.Add("FlowType", typeof(System.Int32));
dt.Columns.Add("PrcsId", typeof(System.Int32));
dt.Columns.Add("UserId", typeof(System.String));
dt.Columns.Add("OpFlag", typeof(System.Int32));
do
{
while (dr.Read())
{
DataRow dtr = dt.NewRow();
dtr["RunId"] = dr["RunId"];
dtr["RunName"] = dr["RunName"];
dtr["FlowId"] = dr["FlowId"];
dtr["BeginUser"] = dr["BeginUser"];
dtr["FlowName"] = dr["FlowName"];
dtr["FlowType"] = dr["FlowType"];
dtr["PrcsId"] = dr["PrcsId"];
dtr["UserId"] = dr["UserId"];
dtr["OpFlag"] = dr["OpFlag"];
dt.Rows.Add(dtr);
}
}
while (dr.NextResult());
return dt;
}
}