E
Earl
I have two tables set up in a parent-child relationship that I display in
the datagrid. I can edit and update the child data columns directly in the
grid -- but not the parent data, as those parent columns are read-only.
Private Sub FillGrid()
DataGrid1.DataSource = Nothing
dsWinMatrix.Reset()
dsWinMatrix.Relations.Clear()
Dim strSQLServer As New SqlConnection(strConnString)
Dim cmd As New SqlCommand("OilCompaniesSelect", strSQLServer)
'a join query that DISTINCTLY matches up all zip IDs
Dim cmdZipMatches As New SqlCommand("OilCompanyZips", strSQLServer)
cmd.CommandType = CommandType.StoredProcedure
cmdZipMatches.CommandType = CommandType.StoredProcedure
cmd.Connection = strSQLServer
cmdZipMatches.Connection = strSQLServer
strSQLServer.Open()
Dim da As New SqlDataAdapter(cmd)
Dim daZip As New SqlDataAdapter(cmdZipMatches)
da.Fill(dsWinMatrix, "dtOilCompanies")
daZip.Fill(dsWinMatrix, "dtOilCompanyZips")
dsWinMatrix.Tables("dtOilCompanies").Columns("OilCompanyID").ColumnMapping =
MappingType.Hidden
dsWinMatrix.Tables("dtOilCompanies").Columns("Tstamp").ColumnMapping =
MappingType.Hidden
dsWinMatrix.Tables("dtOilCompanies").Columns("ZipCityStateID").ColumnMapping
= MappingType.Hidden
dsWinMatrix.Tables("dtOilCompanyZips").Columns("ZipCityStateID").ColumnMapping
= MappingType.Hidden
rel = New DataRelation("ZipCityState_OilCompanies", _
dsWinMatrix.Tables("dtOilCompanyZips").Columns("ZipCityStateID"), _
dsWinMatrix.Tables("dtOilCompanies").Columns("ZipCityStateID"), False)
dsWinMatrix.Relations.Add(rel)
dsWinMatrix.Tables("dtOilCompanies").Columns.Add("City", GetType(String),
"Parent(ZipCityState_OilCompanies).City")
dsWinMatrix.Tables("dtOilCompanies").Columns.Add("State", GetType(String),
"Parent(ZipCityState_OilCompanies).State")
dsWinMatrix.Tables("dtOilCompanies").Columns.Add("Zip", GetType(String),
"Parent(ZipCityState_OilCompanies).Zip")
DataGrid1.DataSource = dsWinMatrix.Tables("dtOilCompanies")
cm = CType(Me.BindingContext(dsWinMatrix.Tables("dtOilCompanies")),
CurrencyManager)
AdjustTableStyle()
End Sub
the datagrid. I can edit and update the child data columns directly in the
grid -- but not the parent data, as those parent columns are read-only.
Private Sub FillGrid()
DataGrid1.DataSource = Nothing
dsWinMatrix.Reset()
dsWinMatrix.Relations.Clear()
Dim strSQLServer As New SqlConnection(strConnString)
Dim cmd As New SqlCommand("OilCompaniesSelect", strSQLServer)
'a join query that DISTINCTLY matches up all zip IDs
Dim cmdZipMatches As New SqlCommand("OilCompanyZips", strSQLServer)
cmd.CommandType = CommandType.StoredProcedure
cmdZipMatches.CommandType = CommandType.StoredProcedure
cmd.Connection = strSQLServer
cmdZipMatches.Connection = strSQLServer
strSQLServer.Open()
Dim da As New SqlDataAdapter(cmd)
Dim daZip As New SqlDataAdapter(cmdZipMatches)
da.Fill(dsWinMatrix, "dtOilCompanies")
daZip.Fill(dsWinMatrix, "dtOilCompanyZips")
dsWinMatrix.Tables("dtOilCompanies").Columns("OilCompanyID").ColumnMapping =
MappingType.Hidden
dsWinMatrix.Tables("dtOilCompanies").Columns("Tstamp").ColumnMapping =
MappingType.Hidden
dsWinMatrix.Tables("dtOilCompanies").Columns("ZipCityStateID").ColumnMapping
= MappingType.Hidden
dsWinMatrix.Tables("dtOilCompanyZips").Columns("ZipCityStateID").ColumnMapping
= MappingType.Hidden
rel = New DataRelation("ZipCityState_OilCompanies", _
dsWinMatrix.Tables("dtOilCompanyZips").Columns("ZipCityStateID"), _
dsWinMatrix.Tables("dtOilCompanies").Columns("ZipCityStateID"), False)
dsWinMatrix.Relations.Add(rel)
dsWinMatrix.Tables("dtOilCompanies").Columns.Add("City", GetType(String),
"Parent(ZipCityState_OilCompanies).City")
dsWinMatrix.Tables("dtOilCompanies").Columns.Add("State", GetType(String),
"Parent(ZipCityState_OilCompanies).State")
dsWinMatrix.Tables("dtOilCompanies").Columns.Add("Zip", GetType(String),
"Parent(ZipCityState_OilCompanies).Zip")
DataGrid1.DataSource = dsWinMatrix.Tables("dtOilCompanies")
cm = CType(Me.BindingContext(dsWinMatrix.Tables("dtOilCompanies")),
CurrencyManager)
AdjustTableStyle()
End Sub