2011-03-08 49 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