干脆把代码都贴出来吧:
string fieldstring;
string[] fieldarray;
ParameterDiscreteValue dv = new ParameterDiscreteValue();
ParameterFields pfs = new ParameterFields();
ParameterField pf = new ParameterField();
//获取字段名,这里用作实验,随便写
fieldstring = "bcd_id,bookname,ucs_code,isbncode,price ";
fieldarray = fieldstring.Split( ', ');
//获取数据
string cs = "server=172.22.0.13;database=YXBOOK;Trusted_Connection=no;uid=sa;pwd=; ";
SqlConnection sconn = new SqlConnection(cs);
string cmdtext = "select " + fieldstring + " from dict_bookcard where bookname like '%字典 ' ";
SqlCommand scmd = new SqlCommand(cmdtext);
SqlDataAdapter sdapt = new SqlDataAdapter(cmdtext, sconn);
bookcard bk = new bookcard();
sdapt.Fill(bk, "book ");
CrystalReport1 cr1 = new CrystalReport1();
//做字段
for (int i = 0; i < 5; i++)
{
int j = i + 1;
dv.Value = fieldarray[i].ToString();
pf.ParameterFieldName = "f " + j.ToString();
pf.CurrentValues.Add(dv); 《《《-----这里好像有问题