WHAT'S HOT
Prev | Current Page 187 | Next

Jayaram Krishnaswamy

"Beginners Guide to SQL Server Integration Services Using Visual Studio 2005"

Make sure
to add a line continuation character in the second statement if the whole
statement is not in one line.
Public Sub Main()
'
' Add your code here
'
Dim con As New SqlClient.SqlConnection
con.ConnectionString = "Data Source=.;User ID=sa;
password=xxxxxxx;Initial Catalog=MyNorthwind;
Persist Security Info=True;"
con.Open()
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = con
cmd.CommandText = "Select LastName from Employees"
Dim rst As SqlClient.SqlDataReader
rst = cmd.ExecuteReader
Chapter 19
[ 283 ]
Dim i As Integer
i = rst.FieldCount
MsgBox(i)
Dim j As Integer
While rst.Read
MsgBox(rst.Item(j))
End While
Dts.TaskResult = Dts.Results.Success
End Sub
The above code is basically quite simple. The steps are as follows:
Declare a connection object that uses the SQLClient native provider.
Assign the string to this connection. This may be obtained by configuring a
DataReader Source component, and copying the string from the Connection
Manger's property window.
Open the connection.
Declare a SQL Command object.
Assign the above connection to the Command's connection.
Provide the SQL for the Command Text of the above Command. This is
the statement that retrieves the Last Names from the employees table in
the MyNorthwind database on the local SQL Server 2005 declared in the
Connection String.
Declare a SQL DataReader object.
Assign the proceeds of the Command's ExecuteReader method to the SQL
DataReader.


Pages:
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199