hi i have 2 listboxes on 1 form , i want each listbox to display data but from the same sql table/database, my code >
private void addproduct_Load(object sender, EventArgs e)
{
DataSet st = new DataSet();
string strConnectionString = "Data Source=JAMES-PC\\SQLEXPRESS;Initial Catalog=tblproducts;Integrated Security=True";
SqlConnection objconnection = new SqlConnection(strConnectionString);
using (SqlCommand cmd = new SqlCommand("SELECT [name,quantity,code,price] FROM [addproducts]",
objconnection))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(st);
}
}
var empList = st.Tables[0].AsEnumerable().Select(dataRow =>
dataRow.Field<string>("name")).ToList();
listBox1.DataSource = empList;
listBox1.SelectedIndex = 0;
}
so i want to show the quantity in listbox 2 , so ive tried copying the whole code and just change bits here and there, but i get an error on var emplist, tried just adding >
dataRow.Field<string>("name")).ToList();
listBox1.DataSource = empList;
listBox1.SelectedIndex = 0;
and just change the values but no luck, please point out where or what im doing wrong, thanks in advance