首页上一页 1 下一页尾页 4 条记录 1/1页
各位高手帮帮忙,以下问题要如何解决编译器错误消息:
发表在ASP.NET图书答疑
2010-10-11
是否精华
是
否
版块置顶:
是
否
各位高手帮帮忙,以下问题要如何解决
编译器错误消息: CS1061: “System.Data.DataRow”不包含“SeriesID”的定义,并且找不到可接受类型为“System.Data.DataRow”的第一个参数的扩展方法“SeriesID”(是否缺少 using 指令或程序集引用?)
源错误:
行 62: //查询
行 63: var gz = from p in Sunlord101.AsEnumerable()
行 64: [font color=#0000FF]where p.SeriesID = "10101"
[/font]行 65: select p;
行 66: foreach (DataRow p in gz)
源码是:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetDataSet();
}
}
private void GetDataSet()
{
SqlConnection sqlcon = new SqlConnection();
SqlDataAdapter sda;
DataSet ds = new DataSet();
string sqlconstr = "Data Source=...;Initial Catalog=...;User ID=sa;Password=******";
sqlcon.ConnectionString = sqlconstr;
String sqlcmd = "SELECT SeriesID, TypeID, application, impedance, imp, DR, RC, LW, thickness FROM dbo.Sunlord101";
using (sda = new SqlDataAdapter(sqlcmd, sqlcon))
{
try
{
sda.Fill(ds, "Sunlord101");
Session["ds"] = ds;
}
catch (SystemException ex)
{
Response.Write(ex.Message.ToString());
}
}
GridView1.DataSource = ds.Tables["Sunlord101"].DefaultView;
GridView1.DataBind();
}
protected void lnkbtnGz_Click(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["ds"];
//对表中的字符串的区域信息进行设置,将不依赖于区域性
ds.Locale = CultureInfo.InvariantCulture;
//取得DataTable
DataTable Sunlord101 = ds.Tables["Sunlord101"];
try
{
//查询
var gz = from p in Sunlord101.AsEnumerable()
where p.SeriesID = "10101"
select p;
foreach (DataRow p in gz)
{
Response.Write(p.Field<int>("SeriesID")+"..." + p.Field<string>("TypeID") + "..."
+ p.Field<string>("application") + "..." + p.Field<string>("impedance") + "..."
+ p.Field<string>("imp") + "..." + p.Field<float>("DR") + "..."
+ p.Field<int>("RC") + "..." + p.Field<string>("LW") + "..."
+ p.Field<float>("thickness"));
Response.Write("<br>");
}
GridView1.Visible = false;
}
catch (InvalidCastException iex)
{
Response.Write(iex.Message.ToString());
}
catch (IndexOutOfRangeException oex)
{
Response.Write(oex.Message.ToString());
}
catch (NullReferenceException nex)
{
Response.Write(nex.Message.ToString());
}
}
protected void lnkbtnSz_Click(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["ds"];
ds.Locale = CultureInfo.InvariantCulture;
DataTable Sunlord101 = ds.Tables["Sunlord101"];
try
{
var sz = from p in Sunlord101.AsEnumerable()
where p.SeriesID = "10102"
select p;
foreach (DataRow p in sz)
{
Response.Write(p.Field<string>("TypeID") + "..."
+ p.Field<string>("application") + "..." + p.Field<string>("impedance") + "..."
+ p.Field<string>("imp") + "..." + p.Field<float>("DR") + "..."
+ p.Field<int>("RC") + "..." + p.Field<string>("LW") + "..."
+ p.Field<float>("thickness"));
Response.Write("<br>");
}
GridView1.Visible = false;
}
catch (InvalidCastException iex)
{
Response.Write(iex.Message.ToString());
}
catch (IndexOutOfRangeException oex)
{
Response.Write(oex.Message.ToString());
}
catch (NullReferenceException nex)
{
Response.Write(nex.Message.ToString());
}
}
protected void lnkbtnPz_Click(object sender, EventArgs e)
{
。。。。。。
[img src=null/img]
编译器错误消息: CS1061: “System.Data.DataRow”不包含“SeriesID”的定义,并且找不到可接受类型为“System.Data.DataRow”的第一个参数的扩展方法“SeriesID”(是否缺少 using 指令或程序集引用?)
源错误:
行 62: //查询
行 63: var gz = from p in Sunlord101.AsEnumerable()
行 64: [font color=#0000FF]where p.SeriesID = "10101"
[/font]行 65: select p;
行 66: foreach (DataRow p in gz)
源码是:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetDataSet();
}
}
private void GetDataSet()
{
SqlConnection sqlcon = new SqlConnection();
SqlDataAdapter sda;
DataSet ds = new DataSet();
string sqlconstr = "Data Source=...;Initial Catalog=...;User ID=sa;Password=******";
sqlcon.ConnectionString = sqlconstr;
String sqlcmd = "SELECT SeriesID, TypeID, application, impedance, imp, DR, RC, LW, thickness FROM dbo.Sunlord101";
using (sda = new SqlDataAdapter(sqlcmd, sqlcon))
{
try
{
sda.Fill(ds, "Sunlord101");
Session["ds"] = ds;
}
catch (SystemException ex)
{
Response.Write(ex.Message.ToString());
}
}
GridView1.DataSource = ds.Tables["Sunlord101"].DefaultView;
GridView1.DataBind();
}
protected void lnkbtnGz_Click(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["ds"];
//对表中的字符串的区域信息进行设置,将不依赖于区域性
ds.Locale = CultureInfo.InvariantCulture;
//取得DataTable
DataTable Sunlord101 = ds.Tables["Sunlord101"];
try
{
//查询
var gz = from p in Sunlord101.AsEnumerable()
where p.SeriesID = "10101"
select p;
foreach (DataRow p in gz)
{
Response.Write(p.Field<int>("SeriesID")+"..." + p.Field<string>("TypeID") + "..."
+ p.Field<string>("application") + "..." + p.Field<string>("impedance") + "..."
+ p.Field<string>("imp") + "..." + p.Field<float>("DR") + "..."
+ p.Field<int>("RC") + "..." + p.Field<string>("LW") + "..."
+ p.Field<float>("thickness"));
Response.Write("<br>");
}
GridView1.Visible = false;
}
catch (InvalidCastException iex)
{
Response.Write(iex.Message.ToString());
}
catch (IndexOutOfRangeException oex)
{
Response.Write(oex.Message.ToString());
}
catch (NullReferenceException nex)
{
Response.Write(nex.Message.ToString());
}
}
protected void lnkbtnSz_Click(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["ds"];
ds.Locale = CultureInfo.InvariantCulture;
DataTable Sunlord101 = ds.Tables["Sunlord101"];
try
{
var sz = from p in Sunlord101.AsEnumerable()
where p.SeriesID = "10102"
select p;
foreach (DataRow p in sz)
{
Response.Write(p.Field<string>("TypeID") + "..."
+ p.Field<string>("application") + "..." + p.Field<string>("impedance") + "..."
+ p.Field<string>("imp") + "..." + p.Field<float>("DR") + "..."
+ p.Field<int>("RC") + "..." + p.Field<string>("LW") + "..."
+ p.Field<float>("thickness"));
Response.Write("<br>");
}
GridView1.Visible = false;
}
catch (InvalidCastException iex)
{
Response.Write(iex.Message.ToString());
}
catch (IndexOutOfRangeException oex)
{
Response.Write(oex.Message.ToString());
}
catch (NullReferenceException nex)
{
Response.Write(nex.Message.ToString());
}
}
protected void lnkbtnPz_Click(object sender, EventArgs e)
{
。。。。。。
[img src=null/img]