6 Replies - 1148 Views - Last Post: 05 January 2015 - 02:47 PM Rate Topic: -----

#1 Rixterz   User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 166
  • Joined: 26-August 12

DataGridView only adding rows from database, not values

Posted 03 January 2015 - 02:52 PM

Hello,

I'm trying to populate a DataGridView with the values from a .accdb database. The problem I'm having is that although 3 rows are made in the DataGridView as there are 3 in the database, all of the values are blank.

Code:

 Dim con As New OleDbConnection With {.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Ricky\Desktop\Permissions.accdb"}

    Private Sub loadPermissions()

        con.Open()

        Dim da As OleDbDataAdapter
        Dim ds As DataSet
        Dim tables As DataTableCollection
        Dim source1 As New BindingSource
     
        ds = New DataSet
        tables = ds.Tables
        da = New OleDbDataAdapter("SELECT * FROM [Permissions]", con)
        da.Fill(ds, "Permissions")
        Dim view As New DataView(tables(0))
        source1.DataSource = view
        DataGridView1.DataSource = view

        con.Close()

    End Sub



Any help would be greatly appreciated.

-Rixterz

Is This A Good Question/Topic? 0
  • +

Replies To: DataGridView only adding rows from database, not values

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: DataGridView only adding rows from database, not values

Posted 03 January 2015 - 03:10 PM

That code works for me, displaying the rows of a table.

Probably not related to your issue, but you should set the DGV's DataSource to source1, the BindingSource (assuming it is your intention to use this).

Depending on what else might be happening before your code executes, you might set it's DataSource to Nothing, before assigning it as source1, to remove any previous binding.



I just added a DGV to a form, I didn't format it or otherwise change it.
Was This Post Helpful? 2
  • +
  • -

#3 Rixterz   User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 166
  • Joined: 26-August 12

Re: DataGridView only adding rows from database, not values

Posted 03 January 2015 - 03:29 PM

View Postandrewsw, on 03 January 2015 - 03:10 PM, said:

That code works for me, displaying the rows of a table.

Probably not related to your issue, but you should set the DGV's DataSource to source1, the BindingSource (assuming it is your intention to use this).

Depending on what else might be happening before your code executes, you might set it's DataSource to Nothing, before assigning it as source1, to remove any previous binding.



I just added a DGV to a form, I didn't format it or otherwise change it.


This didn't do anything; The values are still blank. The fact that both the database and the table are called "Permissions" shouldn't be the problem as the program knows how many rows there are, just not the values in the rows.

-Rixterz
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1545
  • View blog
  • Posts: 3,871
  • Joined: 01-February 13

Re: DataGridView only adding rows from database, not values

Posted 04 January 2015 - 03:26 AM

Rixterz,

What is the deal with the (-1) rep point you gave to andrewsw. I see nothing offensive about what he posted and even if it did not work for you, you should not give negative points to someone that was being kind and trying to help you. :(

I gave him a (+1) to set it right because, he did not deserve that.

This post has been edited by IronRazer: 04 January 2015 - 03:28 AM

Was This Post Helpful? 2
  • +
  • -

#5 Rixterz   User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 166
  • Joined: 26-August 12

Re: DataGridView only adding rows from database, not values

Posted 05 January 2015 - 08:52 AM

View PostIronRazer, on 04 January 2015 - 03:26 AM, said:

Rixterz,

What is the deal with the (-1) rep point you gave to andrewsw. I see nothing offensive about what he posted and even if it did not work for you, you should not give negative points to someone that was being kind and trying to help you. :(/>/>

I gave him a (+1) to set it right because, he did not deserve that.


...but it says "Was this post helpful?" next to the + and - buttons. I did not find it helpful. Flagging a comment is a different thing altogether.

This is not the sort of thing to post when people will be searching this thread looking for an answer to a programming question.

This post has been edited by Rixterz: 05 January 2015 - 08:54 AM

Was This Post Helpful? -2
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 16481
  • View blog
  • Posts: 65,328
  • Joined: 12-June 08

Re: DataGridView only adding rows from database, not values

Posted 05 January 2015 - 10:42 AM

Ease up everyone on the negative repping. Be aware that different folk have different eyes and may comment on things that you, the OP, may not see as an immediate problem, but the poster may see as something that could be down the line. This does not make the comment unhelpful in the broader sense.

Take a step back and slacken the provincial blinders..
Was This Post Helpful? 3
  • +
  • -

#7 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: DataGridView only adding rows from database, not values

Posted 05 January 2015 - 02:47 PM

The downvote button is really for posts that are trolling, intentionally helpful, or blatantly wrong. If someone provides an outright and obvious poor practice solution, that is worthy of a downvote. Someone taking the time to help you and offering some unrelated suggestions really isn't downvote worthy.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1