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?
– Maniero
@bigown I expected to fill the Combobox with all data from the "server" column of the database, but this data does not appear
– Marlon Pereira
@Marlonleandro: Could you give the name of the database, the table name and the column name? // Avoid SELECT type constructs *
– José Diz
@Josédiz I edited the question, added the details
– Marlon Pereira