Hi Guys,

wondering if someone could help me please, this is probably easy for most, but im a beginner :)

i want to make an array from my dataset

dataset is from (tbl_Employees)

i want the array to hold 3 columns/items = item 1 (Username), item 2 (password) item 3 (Position)

i think i pretty much have the loop figgered out in my head, but i cant seem to fathom on how to build the array, any ideas?

many thanks guys

Recommended Answers

All 3 Replies

Just create a DataSet to hold the table in:

Private Function GetTable() As DataSet
    Dim con As New Data.OleDB.OleDBDataAdapter("YourConnectionStringHere")
    Dim da As New Data.OleDB.OleDBDataAdapter(New Data.OleDB.OleDBCommand("SELECT * FROM tbl_Employees",con)
    Dim ds As New DataSet
        'To reference the table, use ds.Tables("tbl_Employee")
        If ds.Tables("tbl_Employee") IsNot Nothing Then Return ds Else Return New DataSet
    Catch ex As Exception
        con = nothing
        da = nothing
    End Try
End Function

As for the array (If absolutely wanted.)

Dim strAr As New List(Of String)
'To Add a new item to the list, do the following...
'As all arrays, the list will be zeroth based. 
'First index will be 0 and so on...

Hi, thanks for you reply,
how would i then use that?
basically im trying to create a login system, i can find the first "employee" but cant seem to find the next, it just bombs out the program, do you mind having look for me please, probable really obvious to you lol

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim con As New OleDb.OleDbConnection                     '"con" variable holds the Connection Object
        Dim dbProvider As String                                 'creates provider variable
        Dim dbSource As String                                   'creates source vaiable
        Dim ds As New DataSet                                    'sets ds as the new dataset
        Dim da As OleDb.OleDbDataAdapter                         'sets da as the data adapter
        Dim sql As String                                        'creates the sql variable
        Dim username As String
        Dim password As String
        Dim position As String
        Dim userfound As Boolean
        Dim pwdmatch As Boolean
        Dim attempts As Integer

        dbProvider = "Provider = Microsoft.ACE.OLEDB.12.0;"      'specifies the provider technology
        dbSource = "Data Source = C:\Users\ComputerFirstAde\Desktop\Computer First Ade VB.net\Computer First Ade\Computer First Ade\CFA_DB.mdb" 'specifies the path to the Database

        con.ConnectionString = dbProvider & dbSource             'creates the connection string

        con.Open()                                               'opens the database

        userfound = False
        pwdmatch = False
        sql = "SELECT tbl_Employees.emp_Username, tbl_Employees.emp_Password, tbl_Employee_Positions.emppos_Position FROM tbl_Employee_Positions INNER JOIN tbl_Employees ON tbl_Employee_Positions.EmpPosID = tbl_Employees.emp_Positon;"
        'creates a query pulling specified fields from the db  

        da = New OleDb.OleDbDataAdapter(sql, con)                'puts a new data adapter into the variable, and links the sql & con variables
        da.Fill(ds, "Login")                                        'Fills the dataset from thr data adapter

        username = ds.Tables("Login").Rows(0).Item("emp_username")
        password = ds.Tables("Login").Rows(0).Item("emp_Password")
        position = ds.Tables("Login").Rows(0).Item("emppos_Position")

            If username = TextBox1.Text Then

                Label1.Text = "username found"
                userfound = True
                If password = TextBox2.Text Then
                    Label2.Text = "matched"
                    pwdmatch = True
                    If username <> TextBox1.Text Then
                        userfound = False
                        MessageBox.Show("try again")
                    End If
                End If

            End If

        Loop Until userfound = True
        'TextBox1.Text = username
        'TextBox2.Text = password.ToString
        'Label1.Text = position.ToString

        MsgBox("db now open")
        con.Close()                                              'closes the database
        MsgBox("db now closed")

    End Sub
End Class

Hi Guys,

quick update - ive managed to do what was needed :)


commented: Nice! Congratulations! +8
Be a part of the DaniWeb community

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