lorena Posted August 2, 2007 Posted August 2, 2007 I am trying to bind one of two queries to a DataGridView on my windows form. The query pulls in information from two tables (these tables have a master/detail relationship) and I cannot figure out how to make it work. The query will pull in several fields from the master record and several fields from the first associated detail record. Everything I have found is set up for a master/detail situation with the datagridview populated with all the detail records associated with the record from the parent table. I created the query I need and made it part of the dataset but when I try to use that query to bind to the datagridview, it is not one of the choices listed. I hope this is making sense. I am sure there is a way to do this and would appreciate any help. Quote
lorena Posted August 9, 2007 Author Posted August 9, 2007 I figured out how to do what I needed to do. Here is the code I used if anyone else runs into this: Private Sub ReleaseReportForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim reportBindingSource As New BindingSource Dim sqlString As String Me.Text = "OPEN REPORTS FOR JOB NO " & menuForm.jobNoString sqlString = "SELECT TDS_RR_RECORD.RR_NO, TDS_RR_RECORD.PROG_NO, TDS_RR_RECORD.JOB_NO, TDS_RR_RECORD.QTY, " & _ " TDS_RR_RECORD.INITIATOR, TDS_RR_RECORD.INITIATOR_DATE, " & _ " TDS_RR_RECORD.CLOSED_DATE, TDS_RR_LEVEL.PART_NO, " & _ " TDS_RR_LEVEL.PART_NAME " & _ " FROM TDS_RR_RECORD INNER JOIN " & _ " TDS_RR_LEVEL ON TDS_RR_RECORD.RR_NO = TDS_RR_LEVEL.RR_NO " & _ " WHERE (TDS_RR_RECORD.STATUS = 'OPEN') AND (TDS_RR_LEVEL.RR_LEVEL = '1') " & _ " AND (TDS_RR_RECORD.JOB_NO='~') " & _ " ORDER BY TDS_RR_RECORD.JOB_NO" sqlString = Replace(sqlString, "~", menuForm.jobNoString) Try With Me.ReleaseDataGridView .AutoGenerateColumns = True reportBindingSource.DataSource = GetData(sqlString) .DataSource = reportBindingSource .AllowUserToResizeColumns = True .BorderStyle = BorderStyle.Fixed3D End With Catch ex As Exception MessageBox.Show("Error is: " & ex.Message.ToString, "ERROR") End Try End Sub Private Shared Function GetData(ByVal sqlCommand As String) _ As DataTable Dim releaseConnectionString As String = My.Settings.ConnectionString Dim releaseConnection As New OracleConnection(riskReleaseConnectionString) Dim releaseCommand As New OracleCommand(sqlCommand, riskReleaseConnection) Dim releaseAdapter As New OracleDataAdapter releaseAdapter.SelectCommand = riskReleaseCommand Dim reportDataTable As New DataTable reportDataTable.Locale = System.Globalization.CultureInfo.InvariantCulture releaseAdapter.Fill(reportDataTable) Return reportDataTable End Function :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.