用SQL SERVER做数据库,用DataForm Wizard建立父子导航窗口之后,添加,删除,更改等功能全部正常,但导航的定位功能不好,因此想添加一个查询功能,例如父子是用"OrderNo"做关联,如何实现通过"OrderNo"来做一个查询功能?多谢!

解决方案 »

  1.   

    可以查询父表中的记录,若用sql语句控件直接写 where orderid=value即可,winform中的dataform自动生成部分是不生成dataadapter部分的代码的,你可托一个过来,改sql语句就和,如果你是把所有数据fill到ds中的话,可以用parentdatagrid.datasource=ds.tables["tablename"].select("orderid=yourvalue");也可以,子表当然是全部fill了,用象导建立过关系自然就能列出了.
      

  2.   


    DataGrid控件名: grdINVAdjustDetail自动生成的窗口有两个OleDataAdapter,分别用于父子记录的.一个DataSet,一个Connection.我在查询按钮Click事件中改变SelectCommand的Text属性,但是运行时出错.
    出错语句:  grdINVAdjustDetail.DataSource = null;错误信息:
    Additional information: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
    另,上面提到的: parentdatagrid 是自定义的对象名吗?
      

  3.   

    这是自动生成的代码的两个相关功能代码,
    public void FillDataSet(Logistic.DS_InvAdjust dataSet)
    {
    dataSet.EnforceConstraints = false;
    try 
    {
    this.oleDbConnection1.Open();
    // Attempt to fill the dataset through the OleDbDataAdapter1.
    this.oleDbDataAdapter1.Fill(dataSet);
    this.oleDbDataAdapter2.Fill(dataSet);
    } finally 
    { dataSet.EnforceConstraints = true; this.oleDbConnection1.Close();
    } } public void LoadDataSet()
    { Logistic.DS_InvAdjust objDataSetTemp;
    objDataSetTemp = new Logistic.DS_InvAdjust();
    try 
    {
    // Attempt to fill the temporary dataset.
    this.FillDataSet(objDataSetTemp); grdINVAdjustDetail.DataSource = null;
    // Empty the old records from the dataset.
    objDS_InvAdjust.Clear();
    // Merge the records into the main dataset.
    objDS_InvAdjust.Merge(objDataSetTemp);
    grdINVAdjustDetail.SetDataBinding(objDS_InvAdjust, "INVAdjust.R_InvAdjust");
    }