I am trying to fill a ComboBox from a database in access but it does not bring me the data, and it appears all blank
conexiones.registration_conexion connect =
new conexiones.registration_conexion();
DropDownList1.DataValueField = "registration_tool";
DropDownList1.DataTextField = "id";
this.DropDownList1.DataBind();
This is the code I have in connections / registration_conexion
public class registration_conexion
{
public DataTable connect()
{
string myConnectionString = @"C:\Users\gutiece\Desktop\database\" + "Database1.accdb";
DataTable SBTable = new DataTable();
OleDbConnection connection = new OleDbConnection();
OleDbCommand command = new OleDbCommand();
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataSet dataset = new DataSet();
try
{
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
bool ok = System.IO.File.Exists(myConnectionString);
String qry = "SELECT * FROM registration_tool";
command.Connection = connection;
command.CommandText = qry;
adapter.SelectCommand = command;
command.Connection.Open();
OleDbDataReader reader = command.ExecuteReader(); // close conn after
SBTable.Load(reader);
if (!reader.IsClosed)
{
reader.Close();
}
return SBTable;
}
catch (Exception)
{
}
return SBTable;
}
}
Solution
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
conexiones.registration_conexion regconnect = new conexiones.registration_conexion();
conexiones.registration_conexion RESBTable = new conexiones.registration_conexion();
DataTable rdvt = RESBTable.regconnect();
this.Dpo_tool.DataSource = rdvt;
this.Dpo_tool.DataTextField = "tool_id";
this.Dpo_tool.DataSource = rdvt;
this.Dpo_tool.DataBind();
this.Dpo_tool.Items.Insert(0, new ListItem("Herramienta", String.Empty));
this.Dpo_torque.DataSource = rdvt;
this.Dpo_torque.DataTextField = "torque_max";
this.Dpo_torque.DataSource = rdvt;
this.Dpo_torque.DataBind();
this.Dpo_torque.Items.Insert(0, new ListItem("Torque", String.Empty));