Results 1 to 2 of 2

Thread: [RESOLVED] Chosing between tables in a single Database

  1. #1

    Thread Starter
    Join Date
    Jan 2015

    Resolved [RESOLVED] Chosing between tables in a single Database

    So far i've been working with only one table on my Database, now i have to add another tables where i will keep track of user logins ( id, date, time, etc..)

    How can i alternate between the tables in my Database? I have 2 tables; "TestDatabase, and Logins"

    I've been deleting, adding, viewing the same Table since i started my project, now i need to add, rows and columns to the newly added table "Logins", how can i make changes to that specific table without interfering with the one i have already?

    This is how i was connecting when i had a single Table in my Database, this is a search example to fill a datagrid.
            Dim str As String
            str = "select id, nome, acesso from TesteDatabase WHERE id = '" & txtid.Text & "'"
            'str = "select id, nome, acesso from TesteDatabase WHERE id LIKE  '%" & txtid.Text & "'"
            da = New OleDb.OleDbDataAdapter(str, con)
            ds = New DataSet
            da.Fill(ds, "teste")
            DataGridViewID.DataSource = ds.Tables("teste")
    now what i want is to add columns and rows, to the new table, "Logins", how can i set the changes to be made on that table ?

    This is the code i use to add rows and columns to the "TestDatabase" Table on my Database
       PictureBox1.Image.Save("C:\Users\Giovanni\Desktop\fotos\" & txtid.Text & ".bmp")
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow
            dsNewRow = ds.Tables("Teste").NewRow()
            dsNewRow.Item("nome") = txtnome.Text
            dsNewRow.Item("acesso") = txtAcesso.Text
            dsNewRow.Item("id") = txtid.Text
            dsNewRow.Item("data") = Today
            dsNewRow.Item("hora") = TimeOfDay
            da.Update(ds, "Teste")
    This will make changes on the first Table, i want to do this for the other table i just created, any guidance?

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Music city, U.S.A.

    Re: Chosing between tables in a single Database

    You're selecting table information using the following string:
    vb Code:
    1. str = "select id, nome, acesso from TesteDatabase WHERE id = '" & txtid.Text & "'"

    In order to change the table that you select from, you would change the 'FROM' clause of the select statement. i.e. change 'testedatabase' to 'logins'. You will also need to change the 'SELECT' part of the select statement to reflect the field names of the new table. i.e. change 'id, nome, acesso' to whatever the field names are in the 'logins' table.

    As far as adding new rows, you would change:
    vb Code:
    1. dsNewRow = ds.Tables("Teste").NewRow()
    to reflect the new table name. i.e. change 'Teste' to 'logins' Again, here you'll have to change column names as well.
    I always add to the reputation of those whose post are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width