I need to populate a combobox with data from a SQL Server Compact column, the code I have has 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 name of the database is: config-data.sdf / table: server / columns: id, server, bank, user, password.