SQL Command
Example of SqlCommand…
Is necessary to inform the connection and the command that you want to execute.
::[Visual Basic]
Public Function ReadFromDB(ByVal connectionString As String) as SqlDataReader
Dim commandText As String = “SELECT * FROM dbo.Table”
Dim connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(commandText, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
connection.Close()
return reader
End Function
::[C#]
private static SqlDataReader ReadFromDB(string connectionString)
{
string commandText = “SELECT * FROM dbo.Table”;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(commandText, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
connection.Close();
return reader;
}