Answered by:
VB and Outlook Contacts

Question
-
I am trying to import, or copy, the contacts from Outlook into a SQL database using Visual Basic 2005 Express. I do know how to do it using Access VB, but I want it to look professional. Thanks all.
Fred.
Wednesday, September 19, 2007 11:27 PM
Answers
-
Hi Fred,
Based on your post, you need to get the contact items from the Outlook and import the contact items into a SQL database. You can take the two steps to achieve this.
1. Get all contact items from the outlook. Here is the code snippet to get all contact items from the outlook.
Code SnippetDim outlookApp As Microsoft.Office.Interop.Outlook._Application = _
New Microsoft.Office.Interop.Outlook.Application()
Dim cntctFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = _
DirectCast(outlookApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts), _
Microsoft.Office.Interop.Outlook.MAPIFolder)
MessageBox.Show(cntctFolder.Items.Count.ToString)
Dim c As Microsoft.Office.Interop.Outlook.ContactItem
Dim objItems As Microsoft.Office.Interop.Outlook.Items
objItems = cntctFolder.Items
Dim iNumTasks As Integer = objItems.Count
For i As Integer = 1 To iNumTasks
c = objItems(i)
MessageBox.Show(c.FullName.ToString())
Next
2. You need to create the Sql server database. Then you can use the SqlCommand to insert the contact items into the database. Please see the following article:
Best regards,
Riquel.
Monday, September 24, 2007 9:57 AMModerator
All replies
-
You forgot to ask a question.Sunday, September 23, 2007 2:36 PMModerator
-
Sorry, my question is how do I import the contact list into a SQL database using VB 2005 express.
ThanksSunday, September 23, 2007 10:41 PM -
Hi Fred,
Based on your post, you need to get the contact items from the Outlook and import the contact items into a SQL database. You can take the two steps to achieve this.
1. Get all contact items from the outlook. Here is the code snippet to get all contact items from the outlook.
Code SnippetDim outlookApp As Microsoft.Office.Interop.Outlook._Application = _
New Microsoft.Office.Interop.Outlook.Application()
Dim cntctFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = _
DirectCast(outlookApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts), _
Microsoft.Office.Interop.Outlook.MAPIFolder)
MessageBox.Show(cntctFolder.Items.Count.ToString)
Dim c As Microsoft.Office.Interop.Outlook.ContactItem
Dim objItems As Microsoft.Office.Interop.Outlook.Items
objItems = cntctFolder.Items
Dim iNumTasks As Integer = objItems.Count
For i As Integer = 1 To iNumTasks
c = objItems(i)
MessageBox.Show(c.FullName.ToString())
Next
2. You need to create the Sql server database. Then you can use the SqlCommand to insert the contact items into the database. Please see the following article:
Best regards,
Riquel.
Monday, September 24, 2007 9:57 AMModerator