Solved

Connection to database (SQL server) beginner question

Posted on 2008-10-10
5
384 Views
Last Modified: 2012-08-13
Hello,

I just installed MS Sql server express together with Compact management.
Could somebody please give me example code to connect to a .sdf database from vb6?. If possible using DAO?
And in the code please give me an example to SELECT * from table and display the data.

Regards,
Dennis
0
Comment
Question by:Schuttend
5 Comments
 
LVL 26

Expert Comment

by:Zberteoc
ID: 22690819
what is a .sdf database?
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22690849
It's a SQL Compact standalone data file.

Here are some samples:
http://www.connectionstrings.com/?carrier=sqlserver2005ce
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 250 total points
ID: 22704518
OK, Brandon got you a connection string that works with .Net.

Now ... to actually put together a VB6 code snippet ...

dim cn as AdoDB.Connection
dim rs as AdoDB.Recordset
 
set cn = new AdoDb.Connection
cn.ConnectionSTring = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=myPath\myData.sdf;"
 
set rs = new adodb.Recordset
rs.Open "Select * from MyTable", cn
While not rs.Eof
  'Do something with the data
  rs.MoveNext
wend
 
rs.close
set rs = nothing
set cn = nothing

Open in new window

0
 

Author Closing Comment

by:Schuttend
ID: 31504929
thanks!
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22807839
Geez... an assist would have at least been nice.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

680 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