Dim cn As SqlConnectionDim cmdGetAll As SqlCommandDim addAllInfo As SqlDataAdapterDim m_dsWork As DataSet cn = New SqlConnection("User ID=sa;password=sa;Initial Catalog=BankKomp;Data Source=NTS")addAllInfo = New SqlDataAdapter()m_dsWork = New DataSet()cmdGetAll = New SqlCommand("spGetAll", cn)cmdGetAll.CommandType = CommandType.StoredProcedure addAllInfo.SelectCommand = cmdGetAll addAllInfo.TableMappings.Add("Table", "tblMain") addAllInfo.TableMappings.Add("Table1", "tblMain_Child") cn.Open() addAllInfo.Fill(m_dsWork) cn.Close() Dim colSSNP, colSSNE As DataColumncolSSNP = m_dsWork.Tables("tblMain").Columns("id") colSSNE = m_dsWork.Tables("tblMain_Child").Columns("id") 'Создаем первичные ключиDim arPersKey(1) As DataColumnDim arEmplKey(2) As DataColumnarPersKey(0) = colSSNP arEmplKey(0) = colSSNE arEmplKey(1) = m_dsWork.Tables("tblMain_Child").Columns("id1") m_dsWork.Tables("tblMain").PrimaryKey = arPersKey m_dsWork.Tables("tblMain_Child").PrimaryKey = arEmplKey Dim fkSSN As ForeignKeyConstraintfkSSN = New ForeignKeyConstraint("SSNForKey", colSSNP, colSSNE)fkSSN.DeleteRule = Rule.Cascade m_dsWork.Tables("tblMain_Child").Constraints.Add(fkSSN) m_dsWork.Relations.Add("CustOrders", m_dsWork.Tables("tblMain").Columns("ID"), m_dsWork.Tables("tblMain_Child").Columns("ID")) DataGrid1.DataSource = m_dsWork DataGrid1.DataMember = "tblMain" DataGrid1.CaptionText = "tblMain" DataGrid2.DataSource = m_dsWork DataGrid2.DataMember = "tblMain_Child" DataGrid2.CaptionText = "tblMain_Child" После вывода информации в DataGrid2 выводятся все строки из дочерней таблицы а не те что соответствуют ID tblMain, в чем ошибка
Ответить
|