2014-11-24 30 views
-4

我得到2個錯誤。'string'不包含'Fill'的定義,也沒有擴展方法'Fill'可以被發現接受'string'類型的第一個參數

「字符串」中不包含關於「填充」的定義和沒有擴展 方法「填充」接受類型的第一個參數「字符串」可以是 發現

'System.Data.DataRow'沒有包含'Item'的定義,也沒有 擴展方法'Item'接受 類型的第一個參數可以找到'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

錯誤消息是正確的。你有'da.Fill',你期望這個到底做了什麼? 'da'是一個字符串,你的意思是創建一個數據適配器嗎? – 2014-11-24 17:49:53

+0

OHHH是的,這就是我的意思是做我的錯誤什麼'System.Data.DataRow'不包含'Item'的定義和沒有擴展方法'Item'接受類型'System.Data.DataRow的第一個參數'可以找到 – 2014-11-24 17:51:16

+0

*提示*:您收到的錯誤消息包含一個行號。這些數字正好顯示錯誤發生在哪一行。檢查行號以查找發生錯誤的位置。 *提示2 *:其中一個.Item調用與其他調用不同。行號會告訴你哪一個。爲了將來的參考,請包括行號並突出顯示它們在您的問題中所屬的行。由於您的問題缺乏詳細信息,因此您會收到許多低質量的答案。 *提示3 *:'''''='['' – HugoRune 2014-11-24 18:02:18

回答

0
String da = ConfigurationManager 
     .ConnectionStrings["connectionString"].ConnectionString; 

    da.Fill(dtparts); 

你試圖調用一個String對象的填充方法,當你想要一個DataAdapter對象。

這是另一個例子,它代表了你可能試圖做的事。 Populating a DataSet from a DataAdapter

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; 
相關問題