Showing data in forms

jramos

Member
Joined
Apr 2, 2013
Messages
5
Location
Lisboa
Programming Experience
10+
Hello, i'm new programming with VB.Net, so excuse me for my dumb questions...

I'm starting a personal project, to maintain a database in access.
I want to show in a form the records from one table in access, but i don't know how can i do it. I've already searched but can't find anything that fullfill my wishes.

I have the following code:
Private Sub FrmManutencaoSite_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
       ConDb.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\Projetos VB\Sites.accdb"
       Call CarregaDados()
End Sub


Sub CarregaDados()
        ConDb.Open()
        StrSelect = "Select *From Sites"
        Command = New OleDbCommand(StrSelect, ConDb)
        MyDataAdapter = New OleDbDataAdapter(Command)
        MyDataTable = New DataTable("Sites")
        MyDataAdapter.Fill(MyDataTable)
        For Each Row As DataRow In MyDataTable.Rows
            MessageBox.Show(Row.Item("Site"))
        Next
        ConDb.Close()
End Sub

With this code i can see the value of filed "Site" of each record in a message box.

But i want to show all records in a form, with all columns and records, like the following example:


Site Descricao Tipo
aaa hhhhhhhhh xxxxx
bbb zzzzzzzzzz yyyyy
ccc ddddddddd zzzzzz

I know i can use a datagrid, but if a datagrid is the only way to do it, can anyone tell me howto create a datagrid without the wizard.

Again, sorry for my dumb question.

Thanks.
 
Last edited by a moderator:
I suggest that you follow the Data Walkthroughs link in my signature. You'll find plenty of good data access stuff there.

That said, the short answer to your question is to bind your DataTable to a DataGridView, which means assigning the table to the grid's DataSource property.
 
Back
Top