C# “string”不包含“Fill”的定义,并且找不到接受“string”类型的第一个参数的扩展方法“Fill”
我有两个错误 “string”不包含“Fill”的定义,也不包含扩展名 接受类型为“string”的第一个参数的方法“Fill”可以是 发现 及 “System.Data.DataRow”不包含“Item”的定义,也不包含 扩展方法“Item”接受类型为的第一个参数 找不到“System.Data.DataRow” 代码如下:C# “string”不包含“Fill”的定义,并且找不到接受“string”类型的第一个参数的扩展方法“Fill”,c#,asp.net,C#,Asp.net,我有两个错误 “string”不包含“Fill”的定义,也不包含扩展名 接受类型为“string”的第一个参数的方法“Fill”可以是 发现 及 “System.Data.DataRow”不包含“Item”的定义,也不包含 扩展方法“Item”接受类型为的第一个参数 找不到“System.Data.DataRow” 代码如下: public partial class account_Default2 : System.Web.UI.Page { protected void Page_Loa
public partial class account_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("PartNumber");
dt.Columns.Add("Qty");
dt.Columns.Add("Price");
dt.Columns.Add("ExtPrice");
dt.AcceptChanges();
Session["DT"] = dt;
GridView1.Visible = true;
BindGrid();
}
}
private void BindGrid()
{
GridView1.DataSource = Session["DT"];
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
// 1off
WebReference.WebServiceTyped ws = new WebReference.WebServiceTyped();
WebReference.CheckPartStatus pq = new WebReference.CheckPartStatus();
DataTable dttemp = new DataTable();
Session["DT"] = dttemp;
pq = ws.CheckPartNumberStatus(TextBox1.Text, TextBox2.Text, "1", "", "", "1");
string price = pq.Parts[0].Cost.ToString();
DataRow dr = default(DataRow);
dr = dttemp.NewRow();
dr["PartNumber"] = TextBox1.Text;
dr["Qty"] = TextBox3.Text;
dr["Price"] = price;
dr["ExtPrice"] = Convert.ToDouble(TextBox3.Text) * Convert.ToDouble(price);
dttemp.Rows.Add(dr);
Session["DT"] = dttemp;
dttemp = null;
BindGrid();
}
protected void Button2_Click(object sender, EventArgs e)
{
WebReference.WebServiceTyped ws = new WebReference.WebServiceTyped();
WebReference.CheckPartStatus pq = new WebReference.CheckPartStatus();
string sql = "SELECT PartNumber, Qty FROM PackageDetail where Package_Name = 'SILVERADO4'";
DataTable dtparts = new DataTable();
String da = ConfigurationManager
.ConnectionStrings["connectionString"].ConnectionString;
da.Fill(dtparts);
//Dim Parts As String = "RANRS5114,RANRS5116,RANRS5118"
//Dim strs() As String
//strs = Parts.Split(",")
for (int i = 0; i <= dtparts.Rows.Count - 1; i++)
{
DataTable dttemp = new DataTable();
Session["DT"] = dttemp;
pq = ws.CheckPartNumberStatus(dtparts.Rows[i].Item["PartNumber"], "", "1", "", "", "1");
string price = pq.Parts[0].Cost.ToString();
DataRow dr = default(DataRow);
dr = dttemp.NewRow();
dr["PartNumber"] = dtparts.Rows[i].Item["PartNumber"];
dr["Qty"] = dtparts.Rows[i].Item("Qty");
dr["Price"] = price;
dr["ExtPrice"] = dtparts.Rows[i].Item["Qty"] * Convert.ToDouble(price);
dttemp.Rows.Add(dr);
Session["DT"] = dttemp;
dttemp = null;
}
BindGrid();
}
}
如果有人帮助我,我会非常感激的,我已经尽了一切努力来修复它
多谢各位
String da = ConfigurationManager
.ConnectionStrings["connectionString"].ConnectionString;
da.Fill(dtparts);
当您想要一个对象时,您正试图对字符串对象调用Fill方法
下面是另一个示例,其中包含您可能尝试执行的操作的代码 这就是我最后要做的:
dttemp = (DataTable)Session["DT"];
part = (string)dtparts.Rows[i]["PartNumber"];
qty = (string)dtparts.Rows[i]["Qty"];
pq = ws.CheckPartNumberStatus(part, "", "1", "", "", "1");
string price = pq.Parts[0].Cost.ToString();
DataRow dr;
dr = dttemp.NewRow();
dr["PartNumber"] = dtparts.Rows[i]["PartNumber"];
dr["Qty"] = qty;
dr["Price"] = price;
dr["ExtPrice"] = Convert.ToDouble(qty) * Convert.ToDouble(price);
dttemp.Rows.Add(dr);
Session["DT"] = dttemp;
dttemp = null;
错误消息是正确的。你有da.Fill,你到底期望这个做什么?da是一个字符串,您是想创建一个数据适配器吗?OHHH是的,这就是我的错误所在“System.data.DataRow”不包含“Item”的定义,并且没有扩展方法“Item”接受类型为“System.data.DataRow”的第一个参数提示:您收到的错误消息包含行号。这些数字准确地显示了错误发生在哪一行。检查行号以查找发生错误的位置。提示2:您的一个.Item调用与其他调用不同。电话号码会告诉你是哪一个。为便于将来参考,请在您的问题中包括行号并突出显示它们所属的行。因为你的问题缺乏细节,你得到了很多低质量的答案。提示3:!='['谢谢Hugo,但我仍然不明白dtparts.Rows[i].Item[PartNumber]有什么问题为什么你认为错误在那一行?我很怀疑。你有没有试着在错误消息中查找行号?知道错误发生的地方真的很有帮助,我推荐它是不够的。有了这一点和我的第三个提示,你应该能够很快解决这个问题。