Tell me please! Since it was not possible to work with databases at all. There is a plate with two columns both text. how to write a request so that the value is entered into one textBox clicked on the search, we received a corresponding value from the second column. I apologize in advance if I did not correctly set it. I read the info, but I still could not do it for my case.

    2 answers 2

    using System.Data.SqlClient; public string GetData(string param) { string temp; using(SqlConnection connection = new SqlConnection("YourConnectionString")) { connection.Open(); using(SqlCommand command = connection.CreateCommand()) { command.CommandText = string.Format("SELECT Param1 FROM Table WHERE Column = {0}", param); using(SqlReader reader = command.ExecuteReader()) { while(reader.Read()) { temp += (string)reader[1]; } } } connection.Close(); return temp; } } 
    • Yyy, dude, the last line is super in general))) - Torteg
    • This option is a little slow , I would have done it faster - johniek_comp
    • Yes, the last line pleases)) - Yaroslav Schubert
    • The correct class name is Sql Data Reader. - George Lanetz
    • There are no global variables in C #, they are all temporary, which means that the name temp loses the few meaning it had in Pure C. - George Lanetz
     SELECT Column2 FROM SomeTable WHERE Column1 = 'Какой-то текст для поиска' 

    Where Column1 and Column2 are the columns of the SomeTable table