|
As per the subject code 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:
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")
m_daStudents.Fill(m_DataSet)
' 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?
Juan P
|
|
|
|