Now when i press the Button the data doesn't show up in the List box , any help ? i want to get the data from database and show it in a list box , so the user can select items from it. i'm using WPF and SQL server 2008 R2 ..
private void button1_Click(object sender, RoutedEventArgs e) {
SqlConnection myConnection = new SqlConnection("user id=userid;" +
"password=password;server=localhost;" +
"Trusted_Connection=yes;" +
"database=db1; " +
"connection timeout=30");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
try
{
myConnection.Open();
}
catch (Exception ex)
{
textBlock1.Text = "" + (ex.ToString());
}
da.SelectCommand = new SqlCommand("Select * FROM Products", myConnection);
da.Fill(ds,"Products");
listBox1.DataContext = ds;
}