You can use the Command object to retrieve data from a database after you connected to it by using the Connection object. The OleDbCommand class is used to construct the Command object. You will supply the SQL selection statement and the Connecton object. The The data will be stored in the DataReader object by executing the ExcecuteReader method of the OleDbCommand class. Here is an example code that uses OleDbCommand and OleDbDataReader to read an Ms. Access database called databasedic.accdb.
If you will get the data from SQLServer by using the Command and DataReader, you simply need to change from OleDbCommand and OleDbDataReader to SqlCommand and SqlDataReader. You also need to change the connection string to connect to the SQLServer. You might want to read this page to learn to connect SQLServer database.
Dim con As OleDbConnection = Nothing
Dim cmd As OleDbCommand = Nothing
Dim reader As OleDbDataReader = Nothing
con = New OleDbConnection()
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Environment.CurrentDirectory & "\\" & "databasedic.accdb"
cmd = New OleDbCommand("Select * From Dictbl", con)
reader = cmd.ExecuteReader()
Catch e As Exception
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: