Link to home
Start Free TrialLog in
Avatar of Sethi
SethiFlag for India

asked on

Address Book In VB

Address Book In VB

Hi,

I want to create an Address Book in VB. The database can be created on SQL Server or Access.

The user computer may or may not have SQL Server or Microsoft Access.

1. How will my Address Book store data on the user's machine ??

2. Is there any other alternative of storing data ??

Thanks.
Avatar of sridhar_PJ
sridhar_PJ

Avatar of Sethi

ASKER

Can I run the application if the client machine doesn't have Access or SQL Server ?
Yes Sethi, you can run the application even if your machine doesn't have access or SQL Server.

If you use Access Database, then too u don't actually need MS Access in ur client machine.
just a lil tip.
You can use ADO to create recordset at run time that run in memory and don't use a database.
You can then persist the recordset by using the save method; using this method you can also save the data as xml...
Avatar of Sethi

ASKER

bhaspup, i am no able o run the application by using SQL Server, but it is working using Access...Any tips or sample code.
Avatar of Sethi

ASKER

I am still waiting for the way to run my application on the client side without SQL Server.
xcuse me, just a clarification...
It is a stand alone application running on a single machine?
If this is the case SQL Server isn't needed.
If you use the method stated in sridhar_PJ' comment or ADO recordset even Access isn't needed...

ie to create the recordset you do:
(taken directly from MSDN)


   Set rsCustomers = New ADODB.Recordset

   With rsCustomers
      ' Set CustomerID as the primary key.
      .Fields.Append "CustomerID", adChar, 5, adFldRowID
      .Fields.Append "CompanyName", adChar, 40, adFldUpdatable
      .Fields.Append "ContactName", adChar, 30, adFldUpdatable
      .Fields.Append "ContactTitle", adChar, 30, adFldUpdatable
      .Fields.Append "Address", adChar, 60, adFldUpdatable
      .Fields.Append "City", adChar, 15, adFldUpdatable
      .Fields.Append "Region", adChar, 15, adFldMayBeNull
      .Fields.Append "PostalCode", adChar, 10, adFldMayBeNull
      .Fields.Append "Country", adChar, 15, adFldUpdatable
      .Fields.Append "Phone", adChar, 24, adFldUpdatable
      .Fields.Append "Fax", adChar, 24, adFldMayBeNull
      ' Use Keyset cursor type to allow updating records.
      .CursorType = adOpenKeyset
      .LockType = adLockOptimistic
      .Open
   End With

then you have a open recordset not connected to a database...
the next step if you want to load/persist data in a text file is to load data from a text file:

(MSDN, same topic ->Creating a Data-Aware Class that Reads Records from a Delimited Text File)

   Dim fld As ADODB.Field
   Dim strRow As String
   Dim strField As String
   Dim intPos As Integer


   Open "Customers.txt" For Input As #1

   Do Until EOF(1)
      Line Input #1, strRow
      With rsCustomers
         .AddNew
         For Each fld In .Fields
            ' If a tab delimiter is found, field text is to the
            ' left of the delimiter.
            If InStr(strRow, Chr(9)) <> 0 Then
               ' Move position to tab delimiter.
               intPos = InStr(strRow, Chr(9))
               ' Assign field text to strField variable.
               strField = Left(strRow, intPos - 1)
            Else
               ' If a tab delimiter isn't found, field text is the
               ' last field in the row.
               strField = strRow
            End If

            ' Strip off quotation marks.
            If Left(strField, 1) = Chr(34) Then
               strField = Left(strField, Len(strField) - 1)
               strField = Right(strField, Len(strField) - 1)
            End If

            fld.Value = strField

            ' Strip off field value text from text row.
            strRow = Right(strRow, Len(strRow) - intPos)
            intPos = 0

         Next
         .Update
         .MoveFirst
      End With
   Loop
   Close

Now you have populated your recordset with the data you have persisted previously.

If you got MSDN I reccomend that you read the mentioned topic.

If you don't want a text file for your data (you know, users sooner or later will take a look in the text file...) you can:
persist data of from your recordset by using this code example taken from MSDN:

Dim rs as new Recordset
Dim rs2 as new Recordset
Dim c as new Connection
Dim s as new Stream

' Query the Titles table.
c.Open "provider=sqloledb;data source=mydb;initial catalog=pubs;user id=sa;password="
rs.cursorlocation = adUseClient
rs.Open "select * from titles", c, adOpenStatic

' Save to the file in the XML format. Note that if you don't specify
' adPersistXML, a binary format (ADTG) will be used by default.
rs.Save "titles.sav", adPersistXML

' Save the Recordset into the ADO Stream object.
rs.save s, adPersistXML
rs.Close
c.Close

set rs = nothing

' Reopen the file.
rs.Open "titles.sav",,,,adCmdFile
' Open the Stream back into a Recordset.
rs2.open s


Hope this will help

Avatar of Sethi

ASKER

This was a great help and infact a learning experience, but I have a database where I am maintaining relationships between tables, how would I maintain it here...It would be too tedious for me to maintain the application.

Cant we run an application without installing SQL Server on the client side ?

I am looking forward to your answer.
Hi Sethi,
Yes you can run your app and access Sql Server data from windows machine. The ODBC client for Sql server will be there by default in win98 and win2000.
To check goto control panel open Data Sources(ODBC) and click Add button. You will get list of installed drivers. Sql server will be in the list.
Add DSN and access your data.
Regards
Sridhar
Avatar of Sethi

ASKER

Sridhar my question is that I want to run an application created in VB/SQL Server, on a desktop that doesn't have SQL Server installed on it.

I am able to do it with Access, but not with SQL Server. Is it possible with SQL Server.

Even with DSN I have tried but it is not working.
ASKER CERTIFIED SOLUTION
Avatar of sridhar_PJ
sridhar_PJ

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sethi

ASKER

This is what I was looking for. I am greatful to you for this answer.