2011-03-08 51 views
1

希望有人能夠闡明我的問題。我跟着在這裏找到的教程http://msdn.microsoft.com/en-us/library/ms171925(v=VS.100).aspx#Y3500,無法得到這個工作。從datagridview傳遞數據以形成C#

我的代碼如下:

namespace CityCollectionCSharp 
{ 
    public partial class frmSwitch : Form 
    { 
     public frmSwitch() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      // TODO: This line of code loads data into the 'newCityCollectionDataSet.ClientTable' table. You can move, or remove it, as needed. 
      this.clientTableTableAdapter.Fill(this.newCityCollectionDataSet.ClientTable); 
      // TODO: This line of code loads data into the 'newCityCollectionDataSet.PropertyInformation' table. You can move, or remove it, as needed. 
      this.propertyInformationTableAdapter.Fill(this.newCityCollectionDataSet.PropertyInformation); 

     } 

     private void propertyInformationDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 
     { 
      System.Data.DataRowView SelectedRowView; 
      newCityCollectionDataSet.PropertyInformationRow SelectedRow; 

      SelectedRowView = (System.Data.DataRowView)propertyInformationBindingSource.Current; 
      SelectedRow = (newCityCollectionDataSet.PropertyInformationRow)SelectedRowView.Row; 

      frmSummary SummaryForm = new frmSummary(); 
      SummaryForm.LoadCaseNumberKey(SelectedRow.CaseNumberKey); 
      SummaryForm.Show(); 
     } 

     private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 
     { 

      propertyInformationBindingSource.Filter = "ClientKey ='" + comboBox1.SelectedValue + "'"; 
     } 




    } 
} 

這是第一種形式,現在的第二種形式:

namespace CityCollectionCSharp 
{ 
    public partial class frmSummary : Form 
    { 
     public frmSummary() 
     { 
      InitializeComponent(); 
     } 

     private void Form2_Load(object sender, EventArgs e) 
     { 
      // TODO: This line of code loads data into the 'newCityCollectionDataSet.PropertyInformation' table. You can move, or remove it, as needed. 
      this.propertyInformationTableAdapter.Fill(this.newCityCollectionDataSet.PropertyInformation); 

     } 
     internal void LoadCaseNumberKey(String CaseNumber) 
     { 
      propertyInformationTableAdapter.FillByCaseNumberKey(newCityCollectionDataSet.PropertyInformation, CaseNumber); 

     } 
    } 
} 

我有查詢設置爲在propertyInfromationTableAdapter如下:

SELECT  CaseNumberKey, BRTNumber, ParcelNumber, Premises, ClientKey, ParcelNum, Registry, TaxAcctName, StreetCode, CoverDate, OrderDate, Assessment, TaxFrom, TaxTo, TaxOpen, WaterOpen, WaterAcct, WaterTo, WaterFrom, AssessedBeg, AssessedDim, SumNotes, Legal, TotalWater, TotalTax, Type, OPARec, OPADoc, OPADocNum, Recital, Num, Name, Direction, Unit, ProductKey, DateFinished, Finished, Paid, BD, BDPaid, Search, Exam 
FROM   PropertyInformation 
WHERE  (CaseNumberKey = @CaseNumberKey) 

我無法弄清楚我的生活爲什麼這不按照規定工作。當我點擊一條記錄時,它會在表格中傳遞兩個記錄,並始終在我有的第一個記錄中。當我離開綁定導航器時,我只知道這一點。任何幫助將非常感激。

回答

1

每當我有一個問題開始關閉網絡時,它歸結爲我做它/實現它的錯誤,誤解的東西如何工作,因此它會打破反正或如果代碼是從第三方那麼它可能無法啓動或您發現一個錯誤。

這是不可能的MSDN代碼是錯誤的(但不是不可能),所以我會建議斷點嘉豪你已經生產的代碼,如果沒有啓發,那麼我會創建一個全新的項目複製代碼字的單詞可能意味着你看到你出錯的地方,或者如果你得到了這個工作,然後慢慢地複製你破解時必須看到的東西。

+1

我想出了這筆交易是什麼。有一行代碼填充自動插入的視圖,並覆蓋查詢。我刪除了類似this.propertyInformationTableAdapter.Fill(this.newCityCollectionDataSet.PropertyInformation)的代碼行;它解決了問題! – korrowan 2011-03-10 13:22:35