不包含“添加”的定义 [英] does not contain a definition for 'Add'
本文介绍了不包含“添加”的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
'System.Web.UI.MobileControls.List'不包含'Add'的定义,也没有扩展方法'Add'接受类型'System.Web.UI.MobileControls.List'的第一个参数' (你错过了使用指令或汇编引用吗?)
我的代码附在这里。
'System.Web.UI.MobileControls.List' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Web.UI.MobileControls.List' could be found (are you missing a using directive or an assembly reference?)
My code attached here.
protected void Button2_Click(object sender, EventArgs e) {
var l = new List();
sc.Open();
SqlCommand cmd = new SqlCommand("select Fliono from BOND_REG where status='A'", sc);
SqlDataReader SDR = cmd.ExecuteReader();
while (SDR.Read() == true)
{
var item1 = SDR.GetValue(0).ToString();
l.Add(item1);
}
fileexport(l);
updatestaus(l);
SDR.Close();
sc.Close();
}
public void updatestaus(List F)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < F.Items.Count - 2; i++)
{
sb.Append(F.Items[i].ToString() + ",");
}
sb.Append(F.Items[F.Items.Count - 1].ToString());
sc.Close();
sc.Open();
SqlCommand cmd = new SqlCommand("update BOND_REG set status='P' where fliono IN ('" + sb.ToString() + "')", sc);
cmd.ExecuteNonQuery();
sc.Close();
}
public void fileexport(List F)
{
// SDR.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < F.Items.Count - 2; i++)
{
sb.Append(F.Items[i].ToString() + ",");
}
sb.Append(F.Items[F.Items.Count - 1].ToString());
SqlCommand cmd1 = new SqlCommand("select * from BOND_REG where status='A' and Fliono IN ('" + sb.ToString() + "')", sc);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd1;
DataTable datatable = new DataTable();
da.Fill(datatable);
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/bond.rpt"));
crystalReport.SetDataSource(datatable);
ExportOptions rptExportOption;
DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();
string reportFileName = @"C:\pdfd\ st1.pdf";
rptFileDestOption.DiskFileName = reportFileName;
rptExportOption = crystalReport.ExportOptions;
{
rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption.ExportDestinationOptions = rptFileDestOption;
rptExportOption.ExportFormatOptions = rptFormatOption;
}
crystalReport.Export();
}
推荐答案
列表 [ ^ ]表示强类型的对象列表。因此,您必须定义要存储在列表中的对象类型。
List[^] represents a strongly typed list of objects. So, you have to define type of objects you want to store in a list.
List<string> l = new List<string>;
在完全使用之前不要使用var了解类型,它也使得帮助更加困难。但是使用List的通用版本
Don't use "var" until you fully understand types, it also makes giving help harder too. But use the generic version of List
//var l = new List();
List<string> l = new List<string>();
</string></string>
这篇关于不包含“添加”的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文