我收到2个错误。
'串'不包含' Fill'的定义没有延伸 方法'填写'接受类型' string'的第一个参数。可能 结果
和
'的System.Data.DataRow'不包含'项目'的定义和不 扩展方法'项目'接受第一个类型的参数 '的System.Data.DataRow'可以找到
以下是代码:
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();
}
}
如果有人帮助我,我会非常感激,我已经尝试了一切来解决它。
谢谢。
答案 0 :(得分:0)
String da = ConfigurationManager
.ConnectionStrings["connectionString"].ConnectionString;
da.Fill(dtparts);
当您需要DataAdapter对象时,您正尝试在String对象上调用Fill方法。
这是另一个示例,其中包含您可能尝试执行的操作的代码。 Populating a DataSet from a DataAdapter
答案 1 :(得分:0)
这就是我最终做的事情:
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;