Hello!

There is a program - one text block ( nameTextBlock ) and one button ( nextButton ) and SQL .

How to make, that when clicking the button, there was a following value of a line from SQL ?

Here is the code, but it displays only the current value from SQL :

 private void GetSqlData() { string connectionString = @"Data Source=Jama-Dharma\sqlexpress;Initial Catalog=Cars;Integrated Security=True"; SqlConnection sqlConnection = new SqlConnection(connectionString); using (sqlConnection) { string sqlQuery = @"SELECT c.Name FROM CarsCatalog c"; SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection); sqlConnection.Open(); SqlDataReader sqlReader = sqlCommand.ExecuteReader(); while (sqlReader.Read()) { nameTextBlock.Text = sqlReader.GetString(0); } sqlConnection.Close(); } } 

Thank you all in advance!

    1 answer 1

    Use DataTableReader , well, or save your strings from SqlDataReader to some kind of data structure ( List<string> ) and bypass it by the button.