The below example fetches the Productname and Productid from table and fill it into the Listbox
private
void
bindListBox()
{
string connString="Fetch connection string";
string
sql =
"SELECT Productid,Productname FROM Employees"
;
using
(SqlCommand cmd =
new
SqlCommand(sql,
new
SqlConnection(connString)))
{
cmd.Connection.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if
(rdr.HasRows)
{
while
(rdr.Read())
{
ListItem li =
new
ListItem(Convert.ToString(rdr[
"ProductName"
]),
Convert.ToString(rdr[
"Productid"
]));
ListBox1.Items.Add(li);
}
}
}
}