Re: Problems in loading data from an access database into an array



On Jul 26, 8:12 pm, Grinning Crow
<GrinningC...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi

Suppose your database has a table called [Screen] which has columns called
[ScreenID] and [SeatID].

Try this:

Public Sub GetSeatIDs(ByVal Screen As Int32, ByVal DBPath As String,
Optional ByVal DBPassword As String = "")

Dim oleConn As New OleDbConnection
Dim oleCSB As New OleDbConnectionStringBuilder
Dim oleAdapter As New OleDbDataAdapter
Dim dtSeatIDs As New DataTable
Dim arSeatIDs(0) As Int16

'build the connection string
With oleCSB
.Add("Provider", "Microsoft.Jet.OLEDB.4.0")
.Add("Data Source", DBPath)
.PersistSecurityInfo = True
If DBPassword <> "" Then
.Add("Jet OLEDB:Database Password", DBPassword)
End If
End With

'associate the connection string just built with the ole connection
oleConn.ConnectionString = oleCSB.ConnectionString

'set up the data adapter with the sql to retrieve the data
oleAdapter.SelectCommand = New OleDbCommand("SELECT [SeatID] FROM
[Screen] WHERE [ScreenID]=" & Screen)

'associate the adapter with the connection to the database
oleAdapter.SelectCommand.Connection = oleConn

'open the connection
oleConn.Open()

'call the fill command to get the data into the datatable
oleAdapter.Fill(dtSeatIDs)

'copy the data into the array
'(although it might be easier to work with it still in the datatable)
dtSeatIDs.Rows.CopyTo(arSeatIDs, 0)

End Sub

hth

GC



"Fabiyi Olawale" wrote:
Please i'm new in VB.net and i'm designing a Cinema booking and purchase
system..I need to load the seat ID from the database into an array.please
how do i go about it.. or can anyone give me an idea of how i can show seats
are availabele,booked or bought..i'll really appreciate input....
regards
wale fabiyi
Kuala Lumpur,Malaysia- Hide quoted text -

- Show quoted text -

Thanks so much for this...it really helped...so now how do i update
the data i worked with into to array and then write it back finally
into the array

.



Relevant Pages

  • Re: Please help, linking VB to Access
    ... If you are going against a Jet database and will never change then ... Dim DB as ADODB.Connection ' specifying the library.object format helps ... you can use the Data Environment in VB to build a connection string (don't ... use the data environment in any actual applications, ...
    (microsoft.public.vb.general.discussion)
  • Re: Im wondering about have two connections, one inside the other.
    ... Is this the same as what I see called "user default database" ... Sometimes I run the code against SqlServer 2008 and then I use Initial Catalog in the connection string and do not use AttachDBFilename. ... Dim sds As New SqlDataSource(cts.ConnectionString, ...
    (microsoft.public.sqlserver.programming)
  • Re: [SOLVED] Cannot display provider-specific login prompt
    ... scenario where the program wouldn't have to know about the database, ... ConnectionStringBuilder up to a PropertyGrid for the end user to populate), ... details of the connection, for the sake of the program being able to connect ... information about the connection string that I will need. ...
    (microsoft.public.dotnet.framework.adonet)
  • Complicated Connection Problems bewteen ADP and SQL Server
    ... This database ... expertise for getting the user workstations talking to the SQL Server. ... connection would fail and the adp wouldn't be able to talk to the server. ... might be in my ADO connection string. ...
    (microsoft.public.access.adp.sqlserver)
  • Complicated Connection Problem between ADP and SQL Server
    ... This database ... expertise for getting the user workstations talking to the SQL Server. ... connection would fail and the adp wouldn't be able to talk to the server. ... might be in my ADO connection string. ...
    (microsoft.public.sqlserver.connect)