Gi I have a DataGridView which populates from an SQL query just fine in default mode

using these table names

[firstName] [varchar](20) NOT NULL,
	[lastName] [varchar](20) NOT NULL,
	[rentpaid] [decimal](18, 0) NOT NULL,
	[datePaid] [date] NOT NULL,
	[propRef] [varchar](10) NOT NULL,
	[rentDue] [decimal](18, 0) NULL,

I have edited the column headers and set the column names to the same values as my table names yet the data is not showing in form load I have set datagridview.AutoGenerateColumns = False

I know the data is there if I delete datagridview.AutoGenerateColumns = False then the data is shown with the default headings?

any idea why this is happening ?

thanks

m

What is your code to bind the records to grid?

Private bindingSource2 As New BindingSource
    Private Sub RadTextBoxTenantIdSearchPrev_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTextBoxTenantIdSearchPrev.TextChanged
        DataGridViewSearchPrev.DataSource = bindingSource2
        Dim connString As String = My.Settings.strConn
        Dim conn As New SqlConnection(connString)
        Dim ds As New DataSet
        Dim strSQL As String = "SELECT t_id, firstName, LastName, rentPaid, datePaid, rentDue FROM payments WHERE t_id ='" & RadTextBoxTenantIdSearchPrev.Text & "'"
        Dim da As New SqlDataAdapter(strSQL, conn)


        Try
            conn.Open()


            Dim builder As New SqlCommandBuilder(da)
            da.Fill(ds, "payments") 'Needs to be the name of the source table

            If ds.Tables.Count > 0 Then
                bindingSource2.DataSource = ds.Tables(0)
            Else
                RadDesktopAlert1.Show()
                RadDesktopAlert1.CaptionText = "Sorry!"
                RadDesktopAlert1.ContentText = "No results found in database"
            End If
        Catch ex As Exception
            'MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Error !!")
            RadDesktopAlert1.Show()
            RadDesktopAlert1.CaptionText = "Sorry!"
            RadDesktopAlert1.ContentText = "Unable to connect to database, Error: " + ex.Source + ": " + ex.Message
        End Try
        conn.Close()
        da.Dispose()
    End Sub

Usually when we set AutoGenerateColumns = False we plan to create the columns manually.

DataGridViewSearchPrev.columns.add( column )

You wouldn't have a reason to do so, unless default doesn't cover your needs (i.e. you might want combobox as a column)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.