I have the code for a datagridview style but for some reason when I run it, nothing shows up. I know the SQL is correct because I've debugged and gotten the SQL statement and executed it in Access and it does return values.
Please tell me what I am doing wrong...
Code:Public Sub FillProdWellData() DataGridView1.Visible = False dgWellData.BringToFront() dgWellData.Visible = True Dim cmdFillProd As New OleDbCommand Dim refNum As Integer dsWellData.Clear() 'the sql statement that retrieves the data from the database in table Param_Prod cmdFillProd.CommandText = "SELECT Distinct API, StartDate, EndDate, Reservoir, " _ & "InitialRate, FinalRate, DeclineRate, DeclineType, HypFactor, " _ & "GasOilRatio, ExtendDate, GasOil, ConstFlVol, InitialWater FROM Param_Prod " _ & "Where Reservoir = '" & Resvr & "' " _ & "AND TemplateName = '" & PrmName & "'" 'the following tells the adapter what the select command is, sets the connection for the cmd and fills the 'dataset with the data returned from the sql statement daWellData.SelectCommand = cmdFillProd cmdFillProd.Connection = gConn Try daWellData.Fill(dsWellData, "Param_Prod") Catch ex As Exception MessageBox.Show(ex.Message) End Try 'tells dcDelete (a data column) that is is the boolean or checkbox. dcDelete.DataType = System.Type.GetType("System.Boolean") dcDelete.DefaultValue = False dcDelete.AllowDBNull = False dcDelete.ColumnName = "Delete" dcDelete.ReadOnly = False 'it should only add the column once not constantly refNum += 1 If refNum = 1 Then dsWellData.Tables("Param_Prod").Columns.Add(dcDelete) End If 'Me.ProdTableStyle() Me.DisplayProdDGV() End SubCode:Public Sub DisplayProdDGV() 'dgWellData.Visible = False 'DataGridView1.Visible = True DataGridView1.Columns.Clear() DataGridView1.AllowUserToAddRows = False DataGridView1.AllowUserToDeleteRows = False Dim Col1 As New DataGridViewComboBoxColumn With Col1 .HeaderText = "API" .Width = 100 '.DataPropertyName = "API" .Items.Add("Y") .Items.Add("N") End With Dim Col2 As New DataGridViewTextBoxColumn With Col2 .HeaderText = "Start Date" .Width = 80 .DataPropertyName = "StartDate" End With Dim Col3 As New DataGridViewTextBoxColumn() With Col3 .HeaderText = "End Date" .Width = 80 .DataPropertyName = "EndDate" End With Dim Col4 As New DataGridViewTextBoxColumn() With Col4 .HeaderText = "Reservoir" .DataPropertyName = "Reservoir" .Width = 100 End With Dim Col5 As New DataGridViewTextBoxColumn() With Col5 .HeaderText = "Initial Rate" .DataPropertyName = "InitialRate" .Width = 80 .DefaultCellStyle.Format = "f2" End With Dim Col6 As New DataGridViewTextBoxColumn() With Col6 .HeaderText = "Final Rate" .DataPropertyName = "FinalRate" .Width = 80 .DefaultCellStyle.Format = "f2" End With Dim Col7 As New DataGridViewTextBoxColumn() With Col7 .HeaderText = "Decline Rate" .DataPropertyName = "DeclineRate" .Width = 80 .DefaultCellStyle.Format = "f4" End With Dim Col8 As New DataGridViewTextBoxColumn() With Col8 .HeaderText = "Decline Type" .DataPropertyName = "DeclineType" .Width = 60 End With Dim Col9 As New DataGridViewTextBoxColumn() With Col9 .DataPropertyName = "HypFactor" .HeaderText = "HypFactor" .Width = 80 .DefaultCellStyle.Format = "f2" End With Dim Col10 As New DataGridViewTextBoxColumn() With Col10 .DataPropertyName = "GasOilRatio" .HeaderText = "Gas\Oil Ratio" .Width = 80 .DefaultCellStyle.Format = "f2" End With Dim Col11 As New DataGridViewTextBoxColumn() With Col11 .DataPropertyName = "ExtendDate" .HeaderText = "Extend Date" .Width = 80 End With Dim Col12 As New DataGridViewTextBoxColumn() With Col12 .DataPropertyName = "GasOil" .HeaderText = "GasOil" .Width = 80 End With Dim Col13 As New DataGridViewTextBoxColumn() With Col13 .DataPropertyName = "ConstFlVol" .HeaderText = "ConstFlVol" .Width = 80 End With Dim col14 As New DataGridViewCheckBoxColumn With col14 .HeaderText = "Delete" .Width = 60 End With Dim col15 As New DataGridViewTextBoxColumn With col15 .DataPropertyName = "InitialWater" .HeaderText = "Initial Water" .Width = 80 End With With DataGridView1.Columns .Add(col14) .Add(Col1) .Add(Col2) .Add(Col3) .Add(Col4) .Add(Col5) .Add(Col6) .Add(Col7) .Add(Col8) .Add(Col9) .Add(Col10) .Add(Col11) .Add(Col12) .Add(Col13) .Add(col15) End With 'DataGridView1.DataSource = RgDataSet2.Tables("ProdInj") DataGridView1.DataSource = dsWellData.Tables("Param_Prod") End Sub




Reply With Quote