Solved

VB, SQL Server, WINDOWS NT...Most Urgent...

Posted on 1998-07-23
3
166 Views
Last Modified: 2010-05-18
I have four different Questions.....

I have two machines...One As WIN-NT SERVER and Other as
WIN-95 client. I have installed the SQL Server 6.5 on the
WIN-NT SERVER.

I have installed the SQL Server Client on WIN-95 machine.
Visual Basic 5.0 - Enterprise edition is also installed on
WIN-95 machine.

Q-1 : How do i connect SQL server running on WIN-NT server
      in my Visual Basic Project ( WIN-95 machine ) ???

Q-2 : How do i open the databases & tables of SQL server  
      from the Visual Basic Project ( WIN-95 machine ) ???

Q-3 : How can i add / modify / delete records in SQL server
      tables ???

Q-4 : How do i query the SQL server tables... ???

I want the answer with detailed example. Ofcourse i do
agree that the points given here are very less...but that
is what i have with me...

Expecting the answers from you experts...

Few more information : WINDOWS-NT DOMAIN : TAPS_DOMAIN
                       SQL Server Name   : NT_SERVER

Kind Regards,

TAPS
0
Comment
Question by:tapsbin
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
waty earned 400 total points
ID: 1466487
Q-1 : How do i connect SQL server running on WIN-NT server
      in my Visual Basic Project ( WIN-95 machine ) ???

You have to create a DSN to establish the connection with your SQL Server (see in your control panel)

In your code do the following (modify the user, pwd, dsn name in
funtion of your database)
Global Const gConnectionString = "ODBC;DATABASE=YourDB;UID=YourUser;PWD=YourPassword;DSN=Your DSNName"

' *** Open database using ODBC
Set DB = OpenDatabase("", dbDriverNoPrompt, False, gConnectionString)


Q-2 : How do i open the databases & tables of SQL server  
      from the Visual Basic Project ( WIN-95 machine ) ???
To establish the connection with the database, see the previous question.

Here is a way to read records in a table
Public Sub ReadInfosUSer()
   Dim sTmp          As String
   Dim record        As Recordset
   Dim sSQL          As String
   
   sSQL = "Select NomD, PrenomD, Titre, Etage, Bureau, Batiment, Fax, Print_Group "
   sSQL = sSQL & "From User "
   sSQL = sSQL & "Where User_Code = '" & gsUserCode & "'"
   
   Set record = DB.OpenRecordset(sSQL, dao.dbOpenForwardOnly, dao.dbSQLPassThrough)
   
   If (record.RecordCount <> 0) Then
      ' *** Infos on the user
     
      gsUserNom = ReadRecordSet(record, "NomD")
      gsUserPrenom = ReadRecordSet(record, "PrenomD")
      gsUserBatiment = ReadRecordSet(record, "Batiment")
      gsUserEtage = ReadRecordSet(record, "Etage")
      gsUserBureau = ReadRecordSet(record, "Bureau")
      gsUserPrintGroup = ReadRecordSet(record, "Print_Group")
      gsUserTitle = ReadRecordSet(record, "Titre")
      gsUserFax = ReadRecordSet(record, "Fax")
   
   End If
   
   record.Close
   Set record = Nothing

End Sub

Q-3 : How can i add / modify / delete records in SQL server
      tables ???
You can use query to add, modify, delete records

Dim sSQL          As String

sSQL = "Delete from YourTable Where (Condition > 50)"
DB.Execute sSQL, DAO.dbSQLPassThrough

sSQL = "Insert into YourTable Values(50)"
DB.Execute sSQL, DAO.dbSQLPassThrough

sSQL = "Update YourTable Set Name = 'TOTO' Where (Condition = 50)"
DB.Execute sSQL, DAO.dbSQLPassThrough

You can also modify, delete or add using a recordset, but it can not use the SQLPassThrough option.

   Dim sTmp          As String
   Dim record        As Recordset
   Dim sSQL          As String
   
   sSQL = "Select NomD, PrenomD, Titre, Etage, Bureau, Batiment, Fax, Print_Group "
   sSQL = sSQL & "From User "
   sSQL = sSQL & "Where User_Code = '" & gsUserCode & "'"
   
   Set record = DB.OpenRecordset(sSQL, dao.dbOpenDynaset)

   if record.EOF = false
      record.Edit
      ...
      record.Update
   end if
   record.Close
   Set record = Nothing


Q-4 : How do i query the SQL server tables... ???
See Question 2

If you need, I can send you a complete sample project wich query a SQL database for tables and generate some code for each table.

0
 

Author Comment

by:tapsbin
ID: 1466488
Thanks,

let me check it out ...on my machines...i will come back to you
tomorrow...

So much thanks,

TAPS

0
 

Author Comment

by:tapsbin
ID: 1466489
Dear waty,

I have defined the DSN ( Data Source Name ) through the Control
Panel....But in server Combo Box it is not displaying the
SQL Server name...even then i added ...

While running your code it gives the message as
Unable to find SQL server .....

Please help...

Please tell me what do i need to check ...to make sure that my
DSN entry is correct...

Kind Regards,

TAPS

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question