Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 27th, 2007, 09:17 PM
Registered User
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Importing Excel Data into a new Dataset

As per the subject title I am trying to create a dataset from scratch - populating with Excel data. I have come across some code that looks like it would do the job (taking two tables and putting them into one dataset):

Program FromDB uses this code to create a DataSet from scratch

Imports System.Data.SqlClient

Public Class Form1

Inherits System.Windows.Forms.Form

' Data adapter for the Students table.

Dim m_daStudents As New SqlDataAdapter( _

"SELECT * FROM Students", _

"User Id=sa;" & _

"Data Source=BENDER\NetSDK;" _

"Initial Catalog=TestScores")

' Data adapter for the TestScores table.

Dim m_daTestScores As New SqlDataAdapter( _

"SELECT * FROM TestScores", _

"User Id=sa;" & _

"Data Source=BENDER\NetSDK;" _

"Initial Catalog=TestScores")

' The DataSet.

Private m_DataSet As New DataSet("Student Scores")

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

' Load the Students table.

m_daStudents.TableMappings.Add("Table", "Students")


' Load the TestScores table naming

' the new table TestScores.

m_daTestScores.Fill(m_DataSet, "TestScores")

' Bind the DataGrid to the DataSet.

DataGrid1.DataSource = m_DataSet

End Sub

End Class

Now I would need to change replace the SqlDataAdapter objects with OleDbDataAdapter objects for excel,.... but I still have another couple of queries on the code:

1. I don't understand what the "User" or the "Initial Catalog" codes in the data adapters does. What is their purpose?

1a. This may be answered above,.... but why are both Initial Catalog = TestScores?

2. Other than using "Students" and "TestScores," what is the difference between the coding

i - m_daStudents.TableMappings.Add("Table","Students")

m_daStudents.Fill(m_DataSet, and

ii - m_daTestScores.Fill(m_DataSet, "TestScores")?

Is there an easier way to do all of this?


Old July 3rd, 2007, 02:18 PM
Authorized User
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post

Have you used the Import/Export Data Task Wizards? (I am 'assuming' you are using SQL 2005 - if you aren't, this won't apply.)

That is the absolute easiest way to populate data from Excel.

Unless, of course, I am not understanding what you are really trying to do ...

The initial catalog is the name of the database you are using.
The user id is exactly what it says.

Old July 4th, 2007, 09:03 PM
Registered User
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

thanks kscase


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing excel data into access forms navdeepsinghparmar Access 1 November 7th, 2007 01:27 PM
Problem importing XML data to Excel bluerattle XML 2 July 3rd, 2007 03:35 PM
Problem importing XML data to Excel bluerattle Excel VBA 0 July 3rd, 2007 03:34 PM
problem in importing data from excel to sql hiren1977 General .NET 0 January 2nd, 2007 06:00 AM
Importing from excel with missing data Lizu SQL Server DTS 4 September 21st, 2004 07:02 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.