今天来结贴,谢谢csdn的朋友,也带来一个问题 :)
private void method_1 ()
{
string aa = "";
string bb = "";
SqlConnection aa = new SqlConnection ( connstr );
aa.open();
SqlCommand cmd = new SqlCommand ( " select col_a from tab_a " ,aa );
SqlDataReader rec = cmd.ExecuteReader ( );
while ( rec.read() )
{
aa =rec[0].tostring();
bb = method_2 ( aa );
}
rec.close();
aa.close();
}
private string method_2 ( string TheCode )
{
string strName = "";
SqlConnection conb = new SqlConnection ( connstr );
conb.open();
SqlCommand cmd = new SqlCommand ( " select col_b from tab_b where code = '"+TheCode+"' " ,conb );
SqlDataReader rec = cmd.ExecuteReader ( );
if ( rec.read() )
{
strName = rec[0].tostring();
rec.close();
conb.close();
return strName;
}
rec.close();
conb.close();
return strName;
}
可是不让同时打开俩个记录集,这种情况怎么办????