Hello to all.

There is a DB, from it I need to get a row that is in the Avto table, the name of the AvtoBazar database. Manage SQL Server CE database. Connect to the database via

SqlCeConnection sqlCE = new SqlCeConnection(@"Data Source=C:\DB\AvtoBazar.sdf;"); 

passes successfully. But there is a string variable in the code that you need to assign a specific value from the Avto table from the NameAvto field. Well, or at least get a collection of values ​​with strings from NameAvto. However, the mind is not enough to understand how to do it. Tell me, please, on the simplest example. Thank.

    1 answer 1

    You need to open a connection

     SqlCeConnection.Open(); 

    After that, create a command object by passing a SQL query and a connection object to it. Execute the query and get the data as an SqlCeDataReader object. In the cycle from the date of the reader you can get the necessary values.

     string sqlQueryString = "Select NameAvto From Avto"; //для конкретного значения добавь Where SqlCeCommand comand = new SqlCeCommand(sqlQueryString, sqlCE); SqlCeDataReader dataReader = comand.executeReader(); List<string> avtoNames = new List<string>(); while(dataReader.Read()){ avtoNames.add(dataReader.getString(0)); } dataReader.close(); 
    • Oh thanks. It helped. Now I will understand the details of this code - Polyakov Sergey