What is the difference between the SqlClient.SqlCommand object and the SqlDataAdapter.SelectCommand object? For instance, if I want to retrieve some rows from a table, the following code works (after instancing connection, command, table, and data-adapter objects):
****************************************
sQueryText = "SELECT * FROM Table"
SQLCatalog = "MyDB"
Server_or_FileName = "MyServer"
With oCn
.ConnectionString = "Initial Catalog=" & SQLCatalog
& ";" & _
"Data Source=" & Server_or_FileName & ";" & _
"Integrated Security=SSPI"
.Open()
End With
oCmd.CommandText = sQueryText
With oDataAdapter
.SelectCommand = oCmd
.SelectCommand.Connection = oCn
.Fill(oTable)
End With
****************************************
But why doesn't this seem to work?:
****************************************
.
.
.
With oDataAdapter
.SelectCommand.CommandType = CommandType.Text
.SelectCommand.CommandText = sQueryText
.SelectCommand.Connection = oCn
.Fill(oTable)
End With
****************************************
Why can't I use the DataAdapter.SelectCommand without first assigning a separate instance of the SQLClient.Command object?
****************************************
sQueryText = "SELECT * FROM Table"
SQLCatalog = "MyDB"
Server_or_FileName = "MyServer"
With oCn
.ConnectionString = "Initial Catalog=" & SQLCatalog
& ";" & _
"Data Source=" & Server_or_FileName & ";" & _
"Integrated Security=SSPI"
.Open()
End With
oCmd.CommandText = sQueryText
With oDataAdapter
.SelectCommand = oCmd
.SelectCommand.Connection = oCn
.Fill(oTable)
End With
****************************************
But why doesn't this seem to work?:
****************************************
.
.
.
With oDataAdapter
.SelectCommand.CommandType = CommandType.Text
.SelectCommand.CommandText = sQueryText
.SelectCommand.Connection = oCn
.Fill(oTable)
End With
****************************************
Why can't I use the DataAdapter.SelectCommand without first assigning a separate instance of the SQLClient.Command object?