Populate combobox with SQL Server Compact data

Asked

Viewed 251 times

0

I need to fill a combobox with data from a column of SQL Server Compact, the code I have not worked.

Class Servidor.cs:

public DataTable Load(string sql)
    {
        Servidor objSqlCeServerDAL = Servidor.GetInstance(connString);
        objSqlCeServerDAL.Open();
        SqlCeDataAdapter dAd = new SqlCeDataAdapter(sql, objSqlCeConnection);
        dAd.SelectCommand.CommandType = CommandType.Text;
        DataSet dSet = new DataSet();
        try
        {
            dAd.Fill(dSet, "servidor");
            return dSet.Tables["servidor"];
        }
        catch
        {
            throw;
        }
        finally
        {
            dSet.Dispose();
            dAd.Dispose();
            objSqlCeServerDAL.Dispose();
        }
    }

Form settings:

try
        {
            Servidor s2 = new Servidor();
            cbServidores.DataSource = s2.Load("Select * from servidor");
            cbServidores.DisplayMember = "servidor";
            cbServidores.ValueMember = "id";
        }
        catch
        {
            MessageBox.Show("Cadastre um servidor!");
        }

The database name is: config-data.sdf / table: server / columns: id, server, database, user, password.

  • What didn’t work? What you expected and what worked?

  • @bigown I expected to fill the Combobox with all data from the "server" column of the database, but this data does not appear

  • @Marlonleandro: Could you give the name of the database, the table name and the column name? // Avoid SELECT type constructs *

  • @Josédiz I edited the question, added the details

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.